Is there an action that is called when a post is restored from the trash?

There are multiple actions. Listed in order of appearance with their parameters: untrash_post – (int) $post_id // before restoring transition_post_status – (string) $new_status, ‘trash’, (object) $post trash_to_{$new_status} – (object) $post // useful to address a special trash to status action untrash_post_comments – (int) $post_id // before associated comments are untrashed untrashed_post_comments – (int) $post_id // … Read more

Is it possible to add an action to the currently running action?

You have to use a later (higher) priority. So use current_filter() to get the current hook and priority, add 1 to that priority, and register the next action: add_action( ‘init’, ‘func_1’ ); function func_1() { global $wp_filter; $hook = current_filter(); add_action( $hook, ‘func_2’, key( $wp_filter[ $hook ] ) + 1 ); } function func_2() { … Read more

Making a class available via actions filters

Build some kind of a registry where other plugins can register new tabs. Let’s say your plugin’s admin page handler is called Main_Controller: class Main_Controller { protected $tabs; public function __construct() { $this->tabs = new Tab_List; do_action( ‘register_tabs’, $this->tabs ); } public function create_tabs() { $all_tabs = $this->tabs->get_tabs(); if ( empty ( $all_tabs ) ) … Read more

Can a plugin add to header/footer/body content?

Hooks are going to be your best friend here. You can filter post content by using the the_content filter for example: add_filter(‘the_content’, ‘wse_174099_append_to_content’); function wse_174099_append_to_content( $content ) { //get your data $custom_items = get_option( ‘option_name’ ); $content .= wpautop( $custom_items ); //always return when using a filter return $content; } You can hook into the … Read more

Actions that Run on Admin Edit Page Load After Posts Are Queried

What actions run on the edit page in the admin section of a post type Here are the do_action and do_action_ref_array calls, for the edit.php (post) screen, without any plugins and with a default theme activated: muplugins_loaded – do_action registered_taxonomy – do_action registered_taxonomy – do_action registered_taxonomy – do_action registered_taxonomy – do_action registered_taxonomy – do_action registered_post_type … Read more

WooCommerce add_action hook results in 500 error

Remove the = sign after your echo statement… echo = “<p>Text Goes Here</p>”; …becomes echo “<p>Text Goes Here</p>”; Final add_action( ‘woocommerce_review_order_after_shipping’, ‘action_woocommerce_review_order_after_shipping’); function action_woocommerce_review_order_after_shipping( ) { echo “<p>Text Goes Here</p>”; }

remove_action not working with procedural function

The issue here is that the child theme functions.php is loaded before the parent theme functions.php. Therefore, the ordering of the add/remove actions would be something like so: //* From the child theme remove_action( ‘wp_head’, ‘func’, 5 ); //* From the parent theme add_action( ‘wp_head’, ‘func’, 5 ); The callback to func on the wp_head … Read more

How to get list of all hooks of current theme / plugin?

As of 2016-09-25, there is no ideal solution. The WP-Parser does the job, but you need to set up a special WP site to run it. WooCommerce’s Hook-docs is something much simpler, and can be easily tweaked. I just wrote a long comment on the topic here: https://github.com/ApiGen/ApiGen/issues/307#issuecomment-249349187

How to register custom post types in a plugin?

The init hook is the first hook allowed. If called earlier it won’t work. See WP Codex: https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/ Create or modify a post type. register_post_type should only be invoked through the ‘init’ action. It will not work if called before ‘init’, and aspects of the newly created or modified post type will work incorrectly if … Read more