Advertisement:

Author Topic: ¿How to use Hooks?  (Read 239 times)

Xefiron

  • Newbie
  • *
  • Posts: 32
  • Software developer - Desarrollador de software
¿How to use Hooks?
« 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.
« Last Edit: March 27, 2019, 01:49:35 am by Xefiron »

cartagena68

  • issues
  • Hero Member
  • *
  • Posts: 1198
Re: ¿How to use Hooks?
« Reply #1 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

Xefiron

  • Newbie
  • *
  • Posts: 32
  • Software developer - Desarrollador de software
Re: ¿How to use Hooks?
« Reply #2 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.
« Last Edit: March 27, 2019, 06:04:55 pm by Xefiron »

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: ¿How to use Hooks?
« Reply #3 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.

Xefiron

  • Newbie
  • *
  • Posts: 32
  • Software developer - Desarrollador de software
Re: ¿How to use Hooks?
« Reply #4 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.