Send an email when custom post type category is changed

Use the hooks added_term_relationship and deleted_term_relationships. These only fire when the relationship changes, as opposed to set_object_terms which always fires: function wpse_181090_object_terms_updated( $object_id ) { static $did = array(); // This function might fire multiple times for the same object, ensure it only runs once if ( ! isset( $did[ $object_id ] ) ) { … Read more

Is there a global action for when a plugin is uninstalled?

No, deactivated_plugin won’t fire during a plugin’s uninstallation process. But there are indeed two hooks that fire when a plugin is uninstalled: pre_uninstall_plugin, which is called right before a plugin is uninstalled. It acts globally, targeting any plugin. uninstall_{$file}, which fires after a specific plugin is uninstalled. Its scope it’s limited to a unique plugin … Read more

Adding an action within a function that is being called by add_filter

The answer when the question is about hooks is always either: timing, priority, or both. Consider the following code: add_action( ‘shutdown’, ‘wpse_258451_shutdown’ ); function wpse_258451_shutdown() { add_action( ‘init’, ‘wpse_258451_init’ ); } function wpse_258451_init() { wp_die( ‘I will never be called.’ ); } It should be obvious that the function wpse_258451_init() will never be called. This … Read more

Restrict access to admin but allow admin_post hook

All you need to do is to modify your method of restricting users. add_action( ‘admin_init’, function() { if ( (defined(‘DOING_AJAX’) && DOING_AJAX) || ( strpos($_SERVER[‘SCRIPT_NAME’], ‘admin-post.php’) ) ) { return; } if ( !current_user_can(‘manage_options’) ) { wp_redirect( home_url(‘/meu-perfil’) ); exit(); } }

How do I know if author field was changed on post save?

Best Hook for that would be wp_insert_post_data function wpse44358_filter_handler( $data , $postarr ){ //do your stuff //if ($data[‘post_author’] == … return data; // make sure you return something } add_filter( ‘wp_insert_post_data’ , ‘wpse44358_filter_handler’ , ’99’, 2 );

Check if action hook exists before adding actions to it

You cannot check if an action will be called before that happens. Even if there were already callbacks attached to the action there would be no guarantee the matching do_action() will be used. In your case, test with is_plugin_active(): if ( is_plugin_active( ‘wordpress-seo/wp-seo.php’ ) ) { // do something } As @Barry Carlyon mentions in … Read more