• Resolved osamaoo7

    (@osamaoo7)


    Hi,
    I noticed that when the request contains $_POST[‘action’]=’heartbeat’ and rewrite rules option is updated in that request the rewrite_rules option will be saved without these sitemap rules:

    [sitemap_index.xml$] => index.php?sitemap=1
    [([^/]+?)-sitemap([0-9]+)?.xml$] => index.php?sitemap=$matches[1]&sitemap_n=$matches[2]
    [([a-z]+)?-?sitemap.xsl$] => index.php?xsl=$matches[1]
    [locations.kml$] => index.php?sitemap=locations

    After debugging the code I found that the constructor of:
    seo-by-rank-math/includes/module/class-manager.php
    has this code:

    public function __construct() {
    if ( Helper::is_heartbeat() ) {
    return;
    }

    $this->action( ‘plugins_loaded’, ‘setup_modules’ );
    $this->filter( ‘rank_math/modules’, ‘setup_core’, 1 );
    $this->filter( ‘rank_math/modules’, ‘setup_admin_only’, 1 );
    $this->filter( ‘rank_math/modules’, ‘setup_internals’, 1 );
    $this->filter( ‘rank_math/modules’, ‘setup_3rd_party’, 1 );

    $this->action( ‘plugins_loaded’, ‘load_modules’ );
    add_action( ‘rank_math/module_changed’, [ ‘\RankMath\Admin\Watcher’, ‘module_changed’ ], 10, 2 );
    $this->action( ‘rank_math/module_changed’, ‘watch_for_analytics’, 10, 2 );
    }

    From the code, it appears that when the request is identified as a heartbeat (Helper::is_heartbeat()), the function exits early without adding the sitemap rules.

    Can you please confirm if this is the intended behavior, or if there is a workaround to ensure that the sitemap rules are properly added even when a heartbeat request updates the rewrite rules?

    Thank you for your assistance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @osamaoo7,

    Thank you for contacting Rank Math support.

    We intentionally don’t run the module’s code on heartbeat requests. Is there a specific reason you want to run the code on heartbeat requests? You could use the following code to overwrite the rewrite rules from functions file and making sure they run only on Heartbeat requests.

    add_action( 'init', function() {
    if ( ! RankMath\Helper::is_heartbeat() ) {
    return;
    }

    global $wp;

    $base = \RankMath\Sitemap\Router::get_sitemap_base();
    $wp->add_query_var( 'sitemap' );
    $wp->add_query_var( 'sitemap_n' );
    $wp->add_query_var( 'xsl' );

    add_rewrite_rule( $base . RankMath\Sitemap\Sitemap::get_sitemap_index_slug() . '\\.xml$', 'index.php?sitemap=1', 'top' );
    add_rewrite_rule( $base . '([^/]+?)-sitemap([0-9]+)?\.xml$', 'index.php?sitemap=$matches[1]&sitemap_n=$matches[2]', 'top' );
    add_rewrite_rule( $base . '([a-z]+)?-?sitemap\.xsl$', 'index.php?xsl=$matches[1]', 'top' );
    }, 1 );

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thread Starter osamaoo7

    (@osamaoo7)

    Hi Rank Math Support Team,

    Thank you for the workaround suggestion and your response.

    While I appreciate the code snippet, my concern is that relying on custom code in my functions file to manage this behavior might lead to potential issues down the line, especially if plugin updates or configuration changes affect the existing rules or their functionality.

    Given that the sitemap rewrite rules are essential for SEO functionality, wouldn’t it make sense for the plugin to handle cases where rewrite rules are modified during heartbeat requests? Embedding this logic directly into the plugin would ensure consistency and reliability across updates.

    Please let me know if it’s possible to consider adding this handling into Rank Math’s core, or if there’s another recommended approach to maintain sitemap rewrite rules across all scenarios.

    Thanks again for your assistance,
    Osama

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @osamaoo7,

    The Heartbeat request is called every 15-120 seconds, and running the rewrite rule on these requests could cause memory issues. That’s why this can’t be implemented in our plugin. Please confirm what you’re trying to achieve by running the rewrite rule code on the Heartbeat requests so we can assist you accordingly.

    Looking forward to helping you.

    Thread Starter osamaoo7

    (@osamaoo7)

    Hello Rank Math Support Team,

    Thank you for clarifying the memory considerations related to running rewrite rules during Heartbeat requests. I understand the performance concerns involved.

    Previously, you provided a workaround for managing sitemap rewrite rules with Heartbeat requests. Given the importance of ensuring consistent sitemap functionality for SEO, I believe this workaround is essential rather than optional.

    Would it be possible to incorporate this workaround directly into the plugin’s core functionality to maintain reliable sitemap rewrite rules across all setups without relying on custom code? I think this would enhance the plugin’s robustness for users who rely on consistent SEO configurations.

    Thank you again for your assistance and support.

    Best regards,
    Osama

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.