The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Wordpress like Hooks (done) - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28) +--- Forum: Modifications and Hackery (https://userspice.com/forums/forumdisplay.php?fid=29) +--- Thread: Wordpress like Hooks (done) (/showthread.php?tid=641) |
Wordpress like Hooks (done) - firestorm - 07-14-2017 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 { 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 { 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); this blog explains the wordpress system which is basically the same here: http://blog.teamtreehouse.com/hooks-wordpress-actions-filters-examples. heres the gist file: https://gist.github.com/Firestorm-Graphics/594d7b759f1b5e2d500a6cc4f33bc75b enjoy RE: Wordpress like Hooks (done) - shoropio - 09-21-2018 One question, does this still work? |