Is there an action for when permalinks are rebuilt?

The action is update_option_permalink_structure. You get the old and the new value as parameters. add_action( ‘update_option_permalink_structure’ , ‘my_custom_function’, 10, 2 ); function my_custom_function( $oldvalue, $_newvalue ) { // do something } There are also the actions update_option_category_base and update_option_tag_base.

How do I print a notice only on certain admin pages?

There is a global variable called $pagenow for the use within WP Admin: global $pagenow; if ( $pagenow == ‘upload.php’ ) : function custom_admin_notice() { echo ‘<div class=”updated”><p>Updated!</p></div>’; } add_action( ‘admin_notices’, ‘custom_admin_notice’ ); endif; UPDATE: Simply include the snippet in your themes or plugins functions.php

Send data to 3rd party api with wp_remote_post on wp_login

The ‘body’ needs to be an array, not including the ‘json_encode($user)’ piece. $response = wp_remote_post( ‘myapp.com/endpoint’, array( ‘method’ => ‘POST’, ‘headers’ => array(‘Content-Type’ => ‘application/json; charset=utf-8’), ‘body’ => $user ) ); I have this in my function since I also had issues with the body being an object: if (is_object($user) && !is_array($user)) $user = json_decode(json_encode($user), … Read more

How to check if which hook triggered the call to a function?

I found the magic code you need. Use current_filter(). This function will return name of the current filter or action. add_action(‘my_test_hook_1′,’my_test_callback_function’); add_action(‘my_test_hook_2′,’my_test_callback_function’); add_action(‘my_test_hook_3′,’my_test_callback_function’); add_action(‘my_test_hook_4′,’my_test_callback_function’); function my_test_callback_function(){ $called_action_hook = current_filter(); // ***The magic code that will return the last called action echo “This function is called by action: ” . $called_action_hook ; } For reference: https://developer.wordpress.org/reference/functions/current_filter/

Add action hook conditionally – only when home.php in use

Use is_home instead, as is_page_template will not work for home.php as its technically not a page template in the traditional sense. add_action(‘template_redirect’, ‘are_we_home_yet’, 10); function are_we_home_yet(){ if ( is_home() ) { //your logic here } } Revised: add_action(‘template_redirect’, ‘are_we_home_yet’, 10); function are_we_home_yet(){ global $template; $template_file = basename((__FILE__).$template); if ( is_home() && $template_file=”home.php” ) { //do … Read more