Action uncanny-automator

automator_rank_math_seo_data_saved

Fires after Rank Math SEO data for an object has been successfully saved.

add_action( 'automator_rank_math_seo_data_saved', $callback, 10, 1 );

Description

Fires after Rank Math SEO data is saved for a post. Developers can use this hook to perform custom actions or trigger automations when SEO metadata is updated, such as logging changes or initiating further processing based on the saved data. The hook passes the post's ID.


Usage

add_action( 'automator_rank_math_seo_data_saved', 'your_function_name', 10, 1 );

Parameters

$object_id (mixed)
This parameter contains the ID of the post whose Rank Math SEO data has just been saved.

Examples

// Example of a function hooked to the 'automator_rank_math_seo_data_saved' action.
// This function will be executed whenever Rank Math SEO data is saved for a post.
function my_automator_rank_math_seo_saved_callback( $object_id ) {
    // Check if the object ID is valid (e.g., a positive integer).
    if ( ! is_numeric( $object_id ) || $object_id <= 0 ) {
        return;
    }

    // Get the post object.
    $post = get_post( $object_id );

    // Ensure we have a valid post object.
    if ( ! $post || 'post' !== $post->post_type ) {
        return;
    }

    // You can now perform actions based on the saved SEO data.
    // For example, you might want to update custom meta fields, log the event,
    // or trigger other automations based on specific SEO score thresholds.

    // Example: Log that SEO data was saved for this post.
    error_log( "Rank Math SEO data saved for post ID: {$object_id} - Title: {$post->post_title}" );

    // Example: If you wanted to check for a specific SEO score (requires fetching the data).
    // You would likely need to use Rank Math's API to get the current SEO score.
    // This is a hypothetical example and might need adjustment based on Rank Math's current API.
    // $seo_score = RankMathHelper::get_score( $object_id );
    // if ( $seo_score && $seo_score >= 80 ) {
    //     error_log( "Post ID {$object_id} has reached a high SEO score ({$seo_score})." );
    // }
}

// Hook the callback function to the action.
// The '3' indicates that the hooked function expects 1 argument (as defined by the action hook).
add_action( 'automator_rank_math_seo_data_saved', 'my_automator_rank_math_seo_saved_callback', 10, 1 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/integrations/seo-by-rank-math/helpers/seo-by-rank-math-helpers.php:64

public function on_rest_metadata_save( $object_id, $object_type, $content ) {
		if ( 'post' !== $object_type ) {
			return;
		}

		do_action( 'automator_rank_math_seo_data_saved', (int) $object_id );
	}

Internal Usage

Found in src/integrations/seo-by-rank-math/triggers/rank-math-seo-score-reached.php:34:

$this->add_action( 'automator_rank_math_seo_data_saved' );

Found in src/integrations/seo-by-rank-math/triggers/rank-math-seo-data-updated.php:27:

$this->add_action( 'automator_rank_math_seo_data_saved' );
Scroll to Top