Osclass forums

Development => Development => Topic started by: Xefiron on March 27, 2019, 01:47:04 am

Title: ¿How to use Hooks?
Post by: Xefiron on March 27, 2019, 01:47:04 am
I create a fairly simple function to do the test

Code: [Select]
function say_hello() {
  echo 'Hello';
}
osc_add_hook('pre_item_post', 'say_hello');

But, when I insert the following code into a form

Code: [Select]
<?php osc_run_hook('pre_item_post'); ?>
The form filled me with codes and error messages, they entered the "Hello" I expected. How am I supposed to call only the Hook that I'm interested in? I'm particularly worried because I want to use the "posted_item" Hook that will run when I post an ad and I do not want all the hooks that are of the type "posted_item" to load.
Title: Re: ¿How to use Hooks?
Post by: cartagena68 on March 27, 2019, 02:59:05 am
May i ask why you need an hook?

If you have the function in function.php or in a plugin you can call directly the function
Code: [Select]
<?php say_hello(); ?>
If you really need an hook you can see this post https://forums.osclass.org/plugins/create-a-new-hook/msg150455/#msg150455
Title: Re: ¿How to use Hooks?
Post by: Xefiron on March 27, 2019, 04:31:41 pm
Could I do that? I guess I'll try. Thanks for your reply.

Edit: I can say that I have actually been able to call the functions in the way you mention. However, I still need to be able to capture a data at the moment a post is made.

Quote
May i ask why you need an hook?

Because I want to be able to retrieve the $ itemId of an ad at the moment it is public, since one of my main functions performs a record in a table at the moment the post of an advertisement is made.
Title: Re: ¿How to use Hooks?
Post by: WEBmods on March 27, 2019, 06:23:51 pm
Hello,

You may want to check the code of some of the free attribute plugins. They capture data from fields on an item and save them to a table on publish.

Regards.
Title: Re: ¿How to use Hooks?
Post by: Xefiron on March 27, 2019, 06:49:51 pm
Quote
You may want to check the code of some of the free attribute plugins. They capture data from fields on an item and save them to a table on publish.

I will do it, thank you very much for the recommendation.