Register hooks in own plugin
-
Hello,
because I don’t like it to download oversized plugins I started writing my own little plugins that i use in my projects.
I have a directory called “my-plugin” inside there is a file called “my-plugin.php” it looks the most time like this:
define("EP_PUSH_DIR", plugin_dir_path( __FILE__ )); define("EP_PUSH_URL", plugin_dir_url(__FILE__)); // include required files require_once(EP_PUSH_DIR . 'class.ep-push.php'); // init the classes add_action( 'init', array( 'ep_push', 'init' ) ); // when admin then include admin class if ( is_admin() ) { require_once(EP_PUSH_DIR . "class.ep-push-admin.php"); add_action("admin_init", array("ep_push_admin", "init")); }
but where I have to define the hooks that i use? in the class init function? Because just now i have a problem with the “wp_insert_post” hook it doesn’t fire… is that the correct way?
class my_plugin_class { public static function init() { add_action("wp_enqueue_scripts", array("my_plugin_class", "my_method")); add_action("wp_insert_post", array("my_plugin_class", "my_method")); add_action("wp_footer", array("my_plugin_class", "my_method")); add_action("wp_header", array("my_plugin_class", "my_method")); } }
is that correct?
- The topic ‘Register hooks in own plugin’ is closed to new replies.