Skip to content

Commit

Permalink
add condition to use new wpseo_debug_markers() filter #95
Browse files Browse the repository at this point in the history
  • Loading branch information
senlin committed Feb 4, 2021
1 parent 39bb461 commit 441613b
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions includes/class-so-clean-up-wp-seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,37 @@ public function so_cuws_remove_menu_item() {
/**
* Upon request by many the plugin now also removes the frontend HTML comments left by Yoast
* improvements of v3.11.1 via [Robert Went](https://gist.github.com/robwent/f36e97fdd648a40775379a86bd97b332)
* v3.14.6: added conditional for new filter tip from [Emanuel-23](https://github.com/senlin/so-clean-up-wp-seo/issues/95)
*
* @since v3.11.0
* @modified v3.11.1
* @modified v3.14.6
*/
public function so_cuws_remove_frontend_html_comments() {

if ( ! empty( $this->options['remove_html_comments'] ) ) {

if ( defined( 'WPSEO_VERSION' ) ) {
add_action( 'get_header', function () { ob_start( function ( $o ) {
return preg_replace( '/\n?<.*?Yoast SEO plugin.*?>/mi', '', $o ); } ); } );
add_action('wp_head',function (){ ob_end_flush(); }, 999);

$wpseo_version = constant( 'WPSEO_VERSION' );

// the wpseo_debug_markers() filter was added in WP SEO version 14.1
if ( $wpseo_version < 14.1 ) {

This comment has been minimized.

Copy link
@Emanuel-23

Emanuel-23 Feb 5, 2021

@senlin
this condition will not work correctly. even if this might look uncritical at first sight, when for example autocasting a string with php to a float and comparing it to the hard coded float value, this might result in unwanted behavior and might be hard to debug afterwards.

I'd strongly suggest to use PHPs version_compare instead.

This comment has been minimized.

Copy link
@senlin

senlin Feb 5, 2021

Author Owner

when for example autocasting a string with php to a float and comparing it to the hard coded float value

sorry, I have no idea what you are talking about.

Please submit a PR on how you propose to do it instead.

Thanks

This comment has been minimized.

Copy link
@Emanuel-23

Emanuel-23 Feb 23, 2021

OK maybe i added to abstract information. the following should be more suitable in this case:

examples:

  1. consider Yoast changed a fictive version string to '14-0' instead of '14.0' (again FICTIVE):
    condition '14-1' < 14.1
    expected output false
    actual output true

    actually for each string that was structured like this ('14-FOONUMBER' i.e. '14-99', the result would be the same: true but expected to be false.
    PHP will autocast the number that is defined in the string. read more about it on https://www.php.net/
  2. consider Yoast added a bugfix for version 14.0 especially and would name it 14.0.1
    condition 14.0.1 < 14.1
    expected output true
    actual output FATAL ERROR syntax error, unexpected '.1'

    actually for each string that was structured like this ('14.FOONUMBER.FOONUMBER' i.e. '14.100.1', the result would be wrong: expected output true or false
    actual output FATAL ERROR syntax error, unexpected '.1'

and so on...

solution

im not going to make a PR for one line sorry

if(version_compare ( $wpseo_version , '14.1', '<' ) )

This comment has been minimized.

Copy link
@senlin

senlin Feb 23, 2021

Author Owner

Many thanks Emmanuel, I now see your point :)
I have just done the update.


add_action( 'get_header', function () { ob_start( function ( $o ) {
return preg_replace( '/\n?<.*?Yoast SEO plugin.*?>/mi', '', $o ); } ); } );
add_action( 'wp_head',function (){ ob_end_flush(); }, 999 );

} else {

add_filter( 'wpseo_debug_markers', '__return_false' );

}

}

}
}
}

/**
* Remove warning notice when changing permalinks
Expand Down

0 comments on commit 441613b

Please sign in to comment.