The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wordpress like Hooks (done)
#1
hey guys, this class will allow us to register hooks and add actions to those hooks, you know, the way wordpress does it.

we first need to drop Hooks.php class file into users/classes folder, if my autoload class has been implemented then no more to do with this, if not then just require_once from init.php.

now we need us_hooks.php to be placed into users/helpers folder, we need to require_once in us_helpers.php above custom_functions.

us_hooks.php is for core hooks and actions, users can use usersc/includes/custom_functions.php for their hooks and actions.in the us_hooks.php file are some helper functions which are required, followed by an example of how to register a hook, and how to action a function on that hook.

user spice could potential have many hooks like:

us_head() // where we could output stylesheets, meta tags etc
us_footer() // we could output js files etc
us_init() // This could be on userspice load
before_login()
after_login()

and so on.

we register a hook like this:
<pre>
Code:
function my_hook {
    do_action('my_hook');
}
</pre>

so my_hook() would be placed into the page or script we want to hook to.
Now we need a function we want to apply to the hook, we can have unlimited number of functions:

<pre>
Code:
function my_function {
    echo "This is my function, Thats awesome !";
}
</pre>


now we assign the function to the hook, which accepts the hook name, function name, priority and args, priority lower the int. the earlier the function is fired :

<pre>
Code:
add_action('my_hook','my_function',10);
</pre>

this blog explains the wordpress system which is basically the same here: http://blog.teamtreehouse.com/hooks-word...s-examples.

heres the gist file:
https://gist.github.com/Firestorm-Graphi...c4f33bc75b

enjoy
  Reply


Messages In This Thread
Wordpress like Hooks (done) - by firestorm - 07-14-2017, 12:36 PM
RE: Wordpress like Hooks (done) - by shoropio - 09-21-2018, 08:06 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)