Remove Yoast SEO Comments - Version 2.0.2

Version Description

  • Added support for Yoast SEO 4.3 and earlier (this includes custom Yoast SEO versions which cannot be updated).
  • Plan B functions added for when Yoast SEO decides to change their coding layout.
Download this release

Release Info

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

Code changes from version 2.0.1 to 2.0.2

Files changed (2) hide show
  1. readme.txt +19 -15
  2. remove-yoast-seo-comments.php +47 -8
readme.txt CHANGED
@@ -14,10 +14,10 @@ A light-weight plugin which will remove the advertisement HTML comments coming f
14
 
15
  `<!-- This site is optimized with the Yoast SEO plugin -->`
16
 
17
- This is a must-have plugin if you have Yoast SEO or Yoast SEO Premium installed.
18
 
19
- = Note =
20
- This plugin requires [Yoast SEO](http://wordpress.org/plugins/wordpress-seo/) or Yoast SEO Premium.
21
 
22
  = Like this plugin? =
23
  If you like this plugin, make sure to rate it 5 stars. Also check out [Remove Google Analytics comments](https://wordpress.org/plugins/remove-google-analytics-comments/)!
@@ -32,11 +32,11 @@ 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.
36
 
37
  = Does this plugin add any configuration options? =
38
 
39
- No, activate the plugin and you are done! This plugin will not add any extra tables or such to your database.
40
 
41
  = Will this plugin modify any of my Yoast SEO plugin files? =
42
 
@@ -44,29 +44,33 @@ No, this plugin will not modify any of your Yoast SEO plugin files.
44
 
45
  == Changelog ==
46
 
 
 
 
 
47
  = 2.0.1 =
48
  * Yoast SEO update caused a bug in this plugin, this update fixes it.
49
 
50
  = 2.0 =
51
- * Introducing more modern, better and faster functions
52
- * RYSC can now be activated without Yoast SEO being activated
53
 
54
  = 1.0.5 =
55
- * Fixed an security vulnerability regarding `target="_blank"` ([read more](https://core.trac.wordpress.org/ticket/36809))
56
- * Added support for WordPress 4.7
57
 
58
  = 1.0.4 =
59
- * Removed debugging code
60
 
61
  = 1.0.3 =
62
- * Removed anonymous functions: RYSC is now more light-weight than ever
63
 
64
  = 1.0.2 =
65
- * Minor changes to all files
66
- * Removed a unnecessary file
67
 
68
  = 1.0.1 =
69
- * Added support for Yoast SEO Premium
70
 
71
  = 1.0 =
72
- * Initial release
14
 
15
  `<!-- This site is optimized with the Yoast SEO plugin -->`
16
 
17
+ This is a must-have plugin if you have Yoast SEO installed.
18
 
19
+ = Note: =
20
+ This plugin requires [Yoast SEO](http://wordpress.org/plugins/wordpress-seo/).
21
 
22
  = Like this plugin? =
23
  If you like this plugin, make sure to rate it 5 stars. Also check out [Remove Google Analytics comments](https://wordpress.org/plugins/remove-google-analytics-comments/)!
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 SEO doesn't change its coding layout. If they do decide to change their coding layout for any reason, the RYSC backup solution will kick in and keep the comments removed.
36
 
37
  = Does this plugin add any configuration options? =
38
 
39
+ No, activate the plugin and you are ready to go!
40
 
41
  = Will this plugin modify any of my Yoast SEO plugin files? =
42
 
44
 
45
  == Changelog ==
46
 
47
+ = 2.0.2 =
48
+ * Added support for Yoast SEO 4.3 and earlier (this includes custom Yoast SEO versions which cannot be updated).
49
+ * Plan B functions added for when Yoast SEO decides to change their coding layout.
50
+
51
  = 2.0.1 =
52
  * Yoast SEO update caused a bug in this plugin, this update fixes it.
53
 
54
  = 2.0 =
55
+ * Introducing more modern, better and faster functions.
56
+ * RYSC can now be activated without Yoast SEO being activated.
57
 
58
  = 1.0.5 =
59
+ * Fixed an security vulnerability regarding `target="_blank"` ([read more](https://core.trac.wordpress.org/ticket/36809)).
60
+ * Added support for WordPress 4.7.
61
 
62
  = 1.0.4 =
63
+ * Removed debugging code.
64
 
65
  = 1.0.3 =
66
+ * Removed anonymous functions.
67
 
68
  = 1.0.2 =
69
+ * Minor changes to all files.
70
+ * Removed a unnecessary file.
71
 
72
  = 1.0.1 =
73
+ * Added support for Yoast SEO Premium.
74
 
75
  = 1.0 =
76
+ * Initial release.
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: 2.0.1
7
  * Author: Mitch
8
  * Author URI: https://profiles.wordpress.org/lowest
9
  * License: GPL-2.0+
@@ -29,14 +29,24 @@
29
 
30
  if ( ! defined( 'ABSPATH' ) ) { exit; }
31
 
 
 
32
  function rysc_bundle() {
33
- if(defined( 'WPSEO_VERSION' ) && class_exists('WPSEO_Frontend')) {
34
- remove_action( 'wpseo_head', array( WPSEO_Frontend::get_instance(), 'debug_mark' ) , 2);
35
- remove_action( 'wp_head', array( WPSEO_Frontend::get_instance(), 'head' ) , 1);
36
- add_action( 'wp_head', 'rysc_rewrite' , 1);
 
 
 
 
 
 
 
 
37
  }
38
  }
39
- add_action( 'init', 'rysc_bundle' );
40
 
41
  function rysc_rewrite() {
42
  $rewrite = new ReflectionMethod( 'WPSEO_Frontend', 'head' );
@@ -44,15 +54,44 @@ function rysc_rewrite() {
44
  $filename = $rewrite->getFileName();
45
  $start_line = $rewrite->getStartLine();
46
  $end_line = $rewrite->getEndLine()-1;
47
-
48
  $length = $end_line - $start_line;
49
  $source = file($filename);
50
  $body = implode("", array_slice($source, $start_line, $length));
51
  $body = preg_replace( '/echo \'\<\!(.*?)\n/', '', $body);
52
-
53
  eval($body);
54
  }
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  function rysc_links( $link ) {
57
  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>') );
58
  }
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.2
7
  * Author: Mitch
8
  * Author URI: https://profiles.wordpress.org/lowest
9
  * License: GPL-2.0+
29
 
30
  if ( ! defined( 'ABSPATH' ) ) { exit; }
31
 
32
+ $GLOBALS['rysc_opts'] = get_option('rysc_options', array());
33
+
34
  function rysc_bundle() {
35
+ if(defined( 'WPSEO_VERSION' ) && class_exists( 'WPSEO_Frontend' )) {
36
+ if(method_exists( 'WPSEO_Frontend', 'debug_mark' ) && version_compare( WPSEO_VERSION, '4.4', '>=' )) { // for Yoast SEO 4.4 or later
37
+ remove_action( 'wpseo_head', array( WPSEO_Frontend::get_instance(), 'debug_mark' ) , 2);
38
+ remove_action( 'wp_head', array( WPSEO_Frontend::get_instance(), 'head' ) , 1);
39
+ add_action( 'wp_head', 'rysc_rewrite' , 1);
40
+ } elseif(method_exists( 'WPSEO_Frontend', 'debug_marker' ) && version_compare( WPSEO_VERSION, '4.3', '<=' )) { // for Yoast SEO 4.3 or earlier
41
+ remove_action( 'wpseo_head', array( WPSEO_Frontend::get_instance(), 'debug_marker' ) , 2);
42
+ remove_action( 'wp_head', array( WPSEO_Frontend::get_instance(), 'head' ) , 1);
43
+ add_action( 'wp_head', 'rysc_rewrite' , 1);
44
+ } else { // looks like we have no compatible solutions for now, let's activate plan b
45
+ add_action( 'wp_head', 'rysc_parser', 999 );
46
+ }
47
  }
48
  }
49
+ add_action( 'init', 'rysc_bundle');
50
 
51
  function rysc_rewrite() {
52
  $rewrite = new ReflectionMethod( 'WPSEO_Frontend', 'head' );
54
  $filename = $rewrite->getFileName();
55
  $start_line = $rewrite->getStartLine();
56
  $end_line = $rewrite->getEndLine()-1;
57
+
58
  $length = $end_line - $start_line;
59
  $source = file($filename);
60
  $body = implode("", array_slice($source, $start_line, $length));
61
  $body = preg_replace( '/echo \'\<\!(.*?)\n/', '', $body);
62
+
63
  eval($body);
64
  }
65
 
66
+ function rysc_parser() {
67
+ $current_cont = ob_get_contents();
68
+
69
+ ob_clean();
70
+
71
+ if(empty($GLOBALS['rysc_opts']['phrase_for_'.WPSEO_VERSION])){
72
+ preg_match_all('/(\n|)\<\!\-\-(.*?)yoast seo(.*?)\-\-\>/i', $current_cont, $result);
73
+
74
+ if (!empty($result[0])) {
75
+ if (!empty($result[0][0])) {
76
+ $GLOBALS['rysc_opts']['phrase_for_'.WPSEO_VERSION]['line1'] = $first_line = $result[0][0];
77
+ }
78
+ if (!empty($result[0][1])) {
79
+ $GLOBALS['rysc_opts']['phrase_for_'.WPSEO_VERSION]['line2'] = $second_line = $result[0][1];
80
+ }
81
+ }
82
+
83
+ update_option('rysc_options', $GLOBALS['rysc_opts']);
84
+ } else {
85
+ $first_line = $GLOBALS['rysc_opts']['phrase_for_'.WPSEO_VERSION]['line1'];
86
+ $second_line = $GLOBALS['rysc_opts']['phrase_for_'.WPSEO_VERSION]['line2'];
87
+ }
88
+
89
+ $current_cont = str_replace( $first_line, '', $current_cont );
90
+ $current_cont = str_replace( $second_line, '', $current_cont );
91
+
92
+ echo $current_cont;
93
+ }
94
+
95
  function rysc_links( $link ) {
96
  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>') );
97
  }