Trigger a custom function when option are saved in admin area

Here is the solution: update_option_{option_name}: Runs after the option with name “option_name” has been updated. For example, for the option with name “foo”: add_action(‘update_option_foo’, ‘my_custom_function’, 10, 2); update_option: Runs before an option gets updated. Example: add_action(‘update_option’, ‘my_custom_function’, 10, 3); updated_option: Runs after an an option has been updated. Example: add_action(‘updated_option’, ‘my_custom_function’, 10, 3);

Send email with custom fields after new draft is saved or new post published

I think you need to handle post request first. You have to do this because gutenberg calls the hook twice. function transition_post_status_handler( $new_status, $old_status, $post ) { if ( defined( ‘REST_REQUEST’ ) && REST_REQUEST ) { send_mail_on_publish( $new_status, $old_status, $post ); set_transient( ‘post_status_updater_flag’, ‘done’, 10 ); } else { if ( false === get_transient( ‘post_status_updater_flag’ … Read more

wp_get_post_terms is difference obj model than the one in rest api response

I got fixed my problem by using the method prepare_item_for_response in WP_REST_Terms_Controller function custome_posts_response(WP_REST_Response $data, WP_POST $post, WP_REST_Request $request) { $newspapers = wp_get_post_terms($post->ID, ‘newspaper’); $categories = wp_get_post_terms($post->ID, ‘category’); $tags = wp_get_post_terms($post->ID, ‘post_tag’); $newspaper_ctrl = new WP_REST_Terms_Controller(‘newspaper’); $category_ctrl = new WP_REST_Terms_Controller(‘category’); $tags_ctrl = new WP_REST_Terms_Controller(‘post_tag’); $newspapers = array_map(function( WP_TERM $newspaper ) use ($newspaper_ctrl, $request) { return … Read more

‘profile_update’ hook alternative for WooCommerce user meta data

My solution would be this: function get_all_user_data($user_id) { $user_data = get_userdata($user_id); $login = $user_data->user_login; $customer_array = new WC_Customer( $user_id ); $customer = $customer_array->get_data(); $billing_first_name = $customer[billing][first_name]; $shipping_first_name = $customer[shipping][first_name]; } add_action(‘user_register’,’get_all_user_data’); add_action(‘profile_update’,’get_all_user_data’); The array setup for the Customer arrays [billing] and [shipping] is as so (you can just change my values and get different data … Read more