Last active
February 2, 2024 18:30
-
-
Save artikus11/0d7a52273bd8bdc85f0d3010f156cd5f to your computer and use it in GitHub Desktop.
Rank Math SEO plugin cleanup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Rank Math SEO plugin cleanup | |
* Description: A cached translation override for WordPress. | |
* Author: Artem Abramovich | |
* Plugin URI: https://gist.github.com/artikus11/0d7a52273bd8bdc85f0d3010f156cd5f | |
* | |
* @link https://rankmath.com/kb/filters-hooks-api-developer/ | |
* | |
* @see https://gist.github.com/timbowen/c5c00667c4c48f8ec3f5706b686d6f00 | |
* @see https://github.com/herewithme/wp-filters-extras | |
* | |
*/ | |
class Art_Rank_Math_Cleanup { | |
public static function init() { | |
define( 'RANK_MATH_PRO_FILE', true ); | |
// Filter to turn off auto-update notification emails. | |
add_filter( 'rank_math/auto_update_send_email', '__return_false' ); | |
// Filter to remove the plugin credit notice added to the source. | |
add_filter( 'rank_math/frontend/remove_credit_notice', '__return_true' ); | |
// Filter to disable adjacent links rel="next" / rel="prev". | |
add_filter( 'rank_math/frontend/disable_adjacent_rel_links', '__return_true' ); | |
// Filter: Prevent Rank Math from changing admin_footer_text. | |
add_action( 'rank_math/whitelabel', '__return_true' ); | |
// Filter to remove sitemap credit. | |
add_filter( 'rank_math/sitemap/remove_credit', '__return_true' ); | |
// Filter to remove `rank-math-link` class from the frontend content links | |
add_filter( 'rank_math/link/remove_class', '__return_true' ); | |
// Filter to hide SEO Score | |
add_filter( 'rank_math/show_score', '__return_false' ); | |
// Filter to hide Analytics Stats bar from the frontend | |
add_filter( 'rank_math/analytics/frontend_stats', '__return_false' ); | |
// Filter to hide the Email Reporting Options | |
add_filter( 'rank_math/analytics/hide_email_report_options', '__return_true' ); | |
// Change the Rank Math Meta Box Priority | |
add_filter( 'rank_math/metabox/priority', static function ( $priority ) { | |
return 'low'; | |
} ); | |
/** | |
* Disable Rank Math admin dashboard news widget. | |
*/ | |
add_action( 'wp_dashboard_setup', static function () { | |
remove_meta_box( 'rank_math_dashboard_widget', 'dashboard', 'normal' ); | |
}, 100 ); | |
/** | |
* Remove Rank Math top menu for admins. | |
*/ | |
add_action( 'wp_before_admin_bar_render', static function () { | |
global $wp_admin_bar; | |
$wp_admin_bar->remove_node( 'rank-math' ); | |
} ); | |
/** | |
* Remove Rank Math upgrade notice. | |
*/ | |
add_action( 'wp_loaded', static function () { | |
self::remove_filters( | |
'admin_notices', | |
'RankMathPro\Plugin_Update\Plugin_Update', | |
'admin_license_notice', | |
20 | |
); | |
} ); | |
/** | |
* Remove Rank Math admin Filter and column score on list tables. | |
*/ | |
add_action( 'wp_loaded', static function () { | |
//Filter score on list tables | |
self::remove_filters( | |
'admin_init', | |
'RankMath\Admin\Post_Filters', | |
'init', | |
10 | |
); | |
//Column score on list tables | |
self::remove_filters( | |
'admin_init', | |
'RankMath\Admin\Post_Columns', | |
'init', | |
10 | |
); | |
} ); | |
} | |
/** | |
* @param $hook_name | |
* @param $class_name | |
* @param $method_name | |
* @param $priority | |
* | |
* @source https://github.com/herewithme/wp-filters-extras | |
* | |
* @return false | |
*/ | |
public static function remove_filters( $hook_name = '', $class_name = '', $method_name = '', $priority = 0 ) { | |
global $wp_filter; | |
// Take only filters on right hook name and priority | |
if ( ! isset( $wp_filter[ $hook_name ][ $priority ] ) || ! is_array( $wp_filter[ $hook_name ][ $priority ] ) ) { | |
return false; | |
} | |
// Loop on filters registered | |
foreach ( (array) $wp_filter[ $hook_name ][ $priority ] as $unique_id => $filter_array ) { | |
// Test if filter is an array ! (always for class/method) | |
if ( isset( $filter_array['function'] ) && is_array( $filter_array['function'] ) ) { | |
// Test if object is a class, class and method is equal to param ! | |
if ( is_object( $filter_array['function'][0] ) | |
&& get_class( $filter_array['function'][0] ) | |
&& get_class( $filter_array['function'][0] ) === $class_name | |
&& $filter_array['function'][1] === $method_name | |
) { | |
// Test for WordPress >= 4.7 WP_Hook class (https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/) | |
if ( is_a( $wp_filter[ $hook_name ], 'WP_Hook' ) ) { | |
unset( $wp_filter[ $hook_name ]->callbacks[ $priority ][ $unique_id ] ); | |
} else { | |
unset( $wp_filter[ $hook_name ][ $priority ][ $unique_id ] ); | |
} | |
} | |
} | |
} | |
return false; | |
} | |
} | |
Art_Rank_Math_Cleanup::init(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment