-
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\Paperclass, which initializes into its ownprivate 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?
The ticket ‘Provide way to reset `Paper` instance’ is closed to new replies.