Advertisement:

Author Topic: Create a new hook  (Read 1293 times)

WillySosa

  • Newbie
  • *
  • Posts: 39
Create a new hook
« on: May 17, 2017, 02:06:14 pm »
Hi everyone, for a new plugin development project, we want to create some new hooks that means instead of using generic osclass hooks like 'item_detail', we want to create our own hooks labels like 'ourhook1'.
How is it feasible?

Web-Media

  • Sr. Member
  • ****
  • Posts: 453
  • Web
Re: Create a new hook
« Reply #1 on: May 17, 2017, 04:34:32 pm »
In your plugin index
Function my_hook (){
   Osc_run_hook('our_hook');
}
Osc_add_hook('item_detail','my_hook');
It's a form  to make available the hook for the next plugins
Firing hook inside the same plugin is not needed ,it's like  instead of writing $var=3, every time you write $var=1+1+1
Who knows about your hook ?
Your plugin  and your following plugins .
Any other plugin cannot know  available hooks from other plugins ,where to fire .. etc .

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: Create a new hook
« Reply #2 on: May 18, 2017, 10:21:11 am »
What the purpose of those hooks?
You could launch as many hooks as you want to with

Code: [Select]
osc_run_hook("your_hook_name", $any_data_if_needed, $another_var);

If you just want to replace "item_detail" by "ourhook1" ... it doesn't make sense, but the solution of web-media should work (but it adds a tiny overhead)

WillySosa

  • Newbie
  • *
  • Posts: 39
Re: Create a new hook
« Reply #3 on: May 21, 2017, 08:05:18 am »
In your plugin index
Function my_hook (){
   Osc_run_hook('our_hook');
}
Osc_add_hook('item_detail','my_hook');
It's a form  to make available the hook for the next plugins
Firing hook inside the same plugin is not needed ,it's like  instead of writing $var=3, every time you write $var=1+1+1
Who knows about your hook ?
Your plugin  and your following plugins .
Any other plugin cannot know  available hooks from other plugins ,where to fire .. etc .
Hi,
I think you didn't understand the question, What I mean is that I am looking for a way to create new hook locations, and they will run wherever I place the osc_run_hook('myhook'); not only at osclass locations like item_detail

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: Create a new hook
« Reply #4 on: May 21, 2017, 09:34:54 am »
"osc_run_hook" will "create" a hook, maybe a better word is to "launch" a hook.

"osc_add_hook" will "attach" functions to a hook that will be executed if/when the hook is "launched" (with osc_run_hook)

You are free to add as many osc_run_hook in your code as you want to

Web-Media

  • Sr. Member
  • ****
  • Posts: 453
  • Web
Re: Create a new hook
« Reply #5 on: May 21, 2017, 11:07:09 am »
To execute osc_run hook ('my_hook) alone must be placed inside theme file or your plugin to have a dedicated page available where you can place  your hooks  .
There is no way to execute  osc_run_hook('my_hook')  from your plugin in the middle of item page  for example without hooking into an already existing hook., or site admin to edit  that page manually and write  osc_run_hook('my_hook')
You cannot fire the hook inside the plugin by finding the current  'action', 'section', page, becouse your plugin maybe is loaded among first and not all the plugins are loaded.
The situation changes if is a theme  or a plugin page
Inside your theme  item file  or your plugin dedicated page you can place hook after hook with no problem ..
osc_run_hook('my_header')
osc_run_hook('header')
osc_run_hook('after_header')
Just keep the well known hooks becouse some plugins do hook there  and removing them will damage some functions.
 A theme is the owner of the layout , plugins just brings some features following the theme rules or complement it by adding new  pages .
A plugin acting like a man in the midle ,catching the request (item page )and redirect into a item page clone inside your plugin cannot be done becouse you cannot guess the current layout . (Bootstrap theme,bender,etc).
Just as i said in the first post ,your hook must be triggered inside a well know hook for well known pages (main,item,user ,etc) or site admin to write by hand as many hooks as he wants into that files .
« Last Edit: May 21, 2017, 11:28:04 am by Web-Media »