Can I use a method from an existing plugin as an action hook?

It sounds like you are looking for do_action() In your method that you wrote add do_action and it will trigger your new custom action. Then you can use add_action() in the same way you use the build in actions. https://developer.wordpress.org/reference/functions/do_action/ Example of your method in the class… public function some_method() { $foo = ‘puppy’; $bar=”bunny”; … Read more

admin_notices not displaying in plugin

Try this. I cleaned up your arg array and placed everything in a function. Also, why are you using the getInstance method when your efpd_admin_notice is public? See the code below for accessing this method properly. function plugin_update(){ $plugin_update = Efpdd::efpd_admin_notice(array( ‘type’ => ‘update’, ‘message’ => ‘The plugin has just been updated.’, ‘button’ => ‘Click … Read more

When to use actions and when to use filters

+1 to both of the other answers, for explaining the primary differences between actions and filters. However, to answer your specific question, about which to use for modifying a query: Injecting your custom query into the template does, as you guessed, require hooking into an existing action. (Whether or not wp_footer is the correct/ideal action … Read more

Admin Hook at the Login Page

If you don’t care about the actual action you can use login_init action like this: add_action( ‘login_init’, ‘wpse8170_login_init’ ); function wpse8170_login_init() { // do your stuff here } But if you want to handle only special actions, then you need to hook into login_form_{action} action, like this: add_action( ‘login_form_login’, ‘wpse8170_login_form_login’ ); function wpse8170_login_form_login() { // … Read more

Get user’s ID on logout

I think I figured this one out. I had misread this answer and hooked the function I wrote to wp_clear_auth_cookie (actually a function itself!) instead of clear_auth_cookie (the real hook), so that wasn’t working. But now using the real hook, I think it might be. Correct me if I’m wrong. Below is the function with … Read more

Mustn’t do_action be accompanied with a function?

The param used in do_action isn’t a function is just a tag that represents the action called, the proper way to use an action is attaching functions with add_action. You can learn more from https://developer.wordpress.org/reference/functions/do_action/

add action wp_head not working

Pull the add_action() outside of the function, and put the conditional inside the callback. Also, if you’re printing a script directly, use wp_print_scripts instead of wp_head. You also have a syntax error. function testingone(){ if( get_option( ‘MyOptionName’ ) ) { ?> <script>var Script = GoesHere; </script> <?php } } add_action( ‘wp_print_scripts’,’testingone’ );