Remove Yoast SEO Comments - Version 2.0

Version Description

  • Introducing more modern, better and faster functions
  • RYSC can now be activated without Yoast SEO activated
Download this release

Release Info

Developer lowest
Plugin Icon wp plugin Remove Yoast SEO Comments
Version 2.0
Comparing to
See all releases

Code changes from version 1.0.5 to 2.0

Files changed (2) hide show
  1. readme.txt +5 -1
  2. remove-yoast-seo-comments.php +25 -29
readme.txt CHANGED
@@ -32,7 +32,7 @@ If you like this plugin, make sure to rate it 5 stars. Also check out [Remove Go
32
 
33
  = When Yoast SEO updates their plugin, will the HTML comments stay removed? =
34
 
35
- Yes, they will stay removed as long as Yoast does not change any file names.
36
 
37
  = Does this plugin add any configuration options? =
38
 
@@ -44,6 +44,10 @@ No, this plugin will not modify any of your Yoast SEO plugin files.
44
 
45
  == Changelog ==
46
 
 
 
 
 
47
  = 1.0.5 =
48
  * Fixed an security vulnerability regarding `target="_blank"` ([read more](https://core.trac.wordpress.org/ticket/36809))
49
  * Added support for WordPress 4.7
32
 
33
  = When Yoast SEO updates their plugin, will the HTML comments stay removed? =
34
 
35
+ Yes, they will stay removed.
36
 
37
  = Does this plugin add any configuration options? =
38
 
44
 
45
  == Changelog ==
46
 
47
+ = 2.0 =
48
+ * Introducing more modern, better and faster functions
49
+ * RYSC can now be activated without Yoast SEO activated
50
+
51
  = 1.0.5 =
52
  * Fixed an security vulnerability regarding `target="_blank"` ([read more](https://core.trac.wordpress.org/ticket/36809))
53
  * Added support for WordPress 4.7
remove-yoast-seo-comments.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Remove Yoast SEO comments
4
  * Plugin URI: https://wordpress.org/plugins/remove-yoast-seo-comments/
5
  * Description: Removes the Yoast SEO advertisement HTML comments from your front-end source code.
6
- * Version: 1.0.5
7
  * Author: Mitch
8
  * Author URI: https://profiles.wordpress.org/lowest
9
  * License: GPL-2.0+
@@ -29,37 +29,33 @@
29
 
30
  if ( ! defined( 'ABSPATH' ) ) { exit; }
31
 
32
- if ( ! defined( 'RYSC_FILE' ) ) { define( 'RYSC_FILE', __FILE__ ); }
33
 
34
- function rysc_active( $plugin ) {
35
- $network_active = false;
36
- if ( is_multisite() ) {
37
- $plugins = get_site_option( 'active_sitewide_plugins' );
38
- if ( isset( $plugins[$plugin] ) ) {
39
- $network_active = true;
40
- }
41
  }
42
- return in_array( $plugin, get_option( 'active_plugins' ) ) || $network_active;
43
  }
 
44
 
45
- if ( rysc_active( 'wordpress-seo/wp-seo.php' ) || rysc_active( 'wordpress-seo-premium/wp-seo-premium.php' ) ) {
46
- add_action('get_header',function (){
47
- ob_start(function ($o) {
48
- return preg_replace('/\n?<.*?yoast.*?>/mi','',$o);
49
- });
50
- });
51
- add_action('wp_head',function (){
52
- ob_end_flush();
53
- }, 999);
54
- } else {
55
- add_action( 'admin_notices', function() {
56
- echo '<div class="notice notice-error is-dismissible"><p>Cannot activate <strong>Remove Yoast SEO comments</strong>: Please activate <a href="http://wordpress.org/plugins/wordpress-seo/" target="_blank">Yoast SEO</a> or Yoast SEO Premium plugin first before activating this plugin.</p></div>';
57
- });
58
- add_action( 'admin_init', function() {
59
- deactivate_plugins( plugin_basename( RYSC_FILE ) );
60
- });
61
  }
62
 
63
- add_filter( 'plugin_action_links_' . plugin_basename( RYSC_FILE ), function($link) {
64
- return array_merge( $link, array('<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2VYPRGME8QELC" target="_blank" rel="noopener noreferrer">Donate</a>') );
65
- } );
 
3
  * Plugin Name: Remove Yoast SEO comments
4
  * Plugin URI: https://wordpress.org/plugins/remove-yoast-seo-comments/
5
  * Description: Removes the Yoast SEO advertisement HTML comments from your front-end source code.
6
+ * Version: 2.0
7
  * Author: Mitch
8
  * Author URI: https://profiles.wordpress.org/lowest
9
  * License: GPL-2.0+
29
 
30
  if ( ! defined( 'ABSPATH' ) ) { exit; }
31
 
32
+ if ( ! defined( 'RYSC_VERSION' ) ) { define( 'RYSC_VERSION', '1.0' ); }
33
 
34
+ function rysc_bundle() {
35
+ if(defined( 'WPSEO_VERSION' ) && class_exists('WPSEO_Frontend')) {
36
+ remove_action( 'wpseo_head', array( WPSEO_Frontend::get_instance(), 'debug_marker' ) , 2);
37
+ remove_action( 'wp_head', array( WPSEO_Frontend::get_instance(), 'head' ) , 1);
38
+ add_action( 'wp_head', 'rysc_rewrite' , 1);
 
 
39
  }
 
40
  }
41
+ add_action( 'init', 'rysc_bundle' );
42
 
43
+ function rysc_rewrite() {
44
+ $rewrite = new ReflectionMethod( 'WPSEO_Frontend', 'head' );
45
+
46
+ $filename = $rewrite->getFileName();
47
+ $start_line = $rewrite->getStartLine();
48
+ $end_line = $rewrite->getEndLine()-1;
49
+
50
+ $length = $end_line - $start_line;
51
+ $source = file($filename);
52
+ $body = implode("", array_slice($source, $start_line, $length));
53
+ $body = preg_replace( '/echo \'\<\!(.*?)\n/', '', $body);
54
+
55
+ eval($body);
 
 
 
56
  }
57
 
58
+ function rysc_links( $link ) {
59
+ return array_merge( $link, array('<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2VYPRGME8QELC" target="_blank" rel="noopener noreferrer">' . __('Donate') . '</a>') );
60
+ }
61
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'rysc_links');