Provide way to reset `Paper` instance

#385277
  • Resolved Dovid Levine
    Rank Math free

    The current way RankMath is coded is heavily coupled with the current request URI, making the plugin almost impossible to extend or use in API contexts.

    A big part of that is due to the reliance on the RankMath\Paper\Paper class, which initializes into its own private static $instance.

    While it would take a major refactor to make the plugin more modular, a good bulk of the issues can be solved easily and _in a non-breaking manner_ by simply adding the following method to the class:

    <?php // includes/frontend/paper/class-paper.php
    /**
     * Clears and reinitializes the object.
     */
    public static function reset() {
    	self::$instance = null;
    	return self::get();
    }

    This could then be used to do the following (just one of a dozen examples. I’m trying to implement a free WPGraphQL API)

    <?php
    // Use RankMath generated description (with settings fallback and replacements) in a custom card loop:
    ...
    foreach( $wp_posts as $posts ) {
    	setup_postdata( $post );
    	\RankMath\Paper\Paper::reset();
            ...
            <div class="excerpt"> <?php echo \RankMath\Paper\Paper::get()->get_description(); ?></div>
    	...
    }

    I really hope you consider adding this to the plugin.

    PS: It seems your github repo is no longer in use. Is there another way for devs to contribute in the spirit of open source?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for contacting Rank Math support, and sorry for the unexpected delays and any inconvenience that might have been caused due to that.

    Allow me to share this with our developers. We should get back to you with an update shortly.

    Looking forward to helping you.

    Hello,

    Thank you for your valuable suggestion. I have added it to our internal to-do list and we’ll make sure to include these changes in the upcoming update.

    https://github.com/rankmath/seo-by-rank-math – This is the public repo where you can contribute the code. The reason it was not updated for the last few months is because we are currently testing the auto-deployment. Please feel free to create PRs there.

    I hope that helps.

    Thanks @Pratik and will do!

    Hello,

    We are super happy that we could address your concern.

    Please do not hesitate to let us know if you need our assistance with anything else.

    Thank you.

    Hello,

    We just wanted to get in touch to let you know that in one of the latest releases of the plugin the developers added a function to reset the Paper class which should help achieve your desired result.

    Hope this helps improve your experience while using the plugin.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘Provide way to reset `Paper` instance’ is closed to new replies.