Support » Plugin: Jetpack by WordPress.com » Resolving Jetpack Conflict with AMP

  • Resolved atomicnicholas

    (@atomicnicholas)


    Hi, Jetpack would fail after I upgraded, and as it turns out, it was a re-declaration of a function that was made with AMP ( shortcode_new_to_old_params() in /jetpack/modules/shortcodes.php ).

    Without having the chance to read the offending code/element in AMP, since the error was in Jetpack, I just added a check in the file via functions_exists() for shortcode_new_to_old_params’ which didn’t exist earlier:

    
    if ( ! function_exists( 'shortcode_new_to_old_params' ) ) {
    	function shortcode_new_to_old_params( $params, $old_format_support = false ) {
    		$str = '';
    
    		if ( $old_format_support && isset( $params[0] ) ) {
    			$str = ltrim( $params[0], '=' );
    		} elseif ( is_array( $params ) ) {
    			foreach ( array_keys( $params ) as $key ) {
    				if ( ! is_numeric( $key ) ) {
    					$str = $key . '=' . $params[ $key ];
    				}
    			}
    		}
    
    		return str_replace( array( '&', '&' ), '&', $str );
    	}
    }
    

    Just wanted to add that here as reference, hopefully for future updates if this is relevant, but also to make sure from your feedback there there won’t be any known (or apparent) conflicts made by this particular action.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Brandon Kraft

    (@kraftbj)

    Code Wrangler

    Howdy!

    Can you include the error message, specifically noting where it was already declared. I did a quick look but didn’t see where it was declared in the AMP plugin that would be conflicting. I want to make sure we’re addressing the right thing (and in this case, if it is our AMP plugin, I’d think we’d want to address is there since there are already some other plugins checking for and using the current function in Jetpack).

    Thanks!

    Hi Brandon, Thanks for looking into this.

    Unfortunately, I was not able to make a copy of the error message, just that it occurred when I disabled Jetpack and re-enabled it. At first I suspected it had to do with my (older) theme, but after changing themes to a default ‘twentyXteen’ one, the symptom persisted.

    All I recall is looking specifically in the error message that stated AMP at issue, but specifically noting the ‘shortcode_new_to_old_params’ being declared twice, being redeclared in ‘/jetpack/modules/shortcodes.php’ …

    So to fix this, I enclosed the function in the ‘if’ check:

    
    if ( ! function_exists( 'shortcode_new_to_old_params' ) ) {
         ...
    }
    

    (noting there no such check in the code) in the file (/jetpack/modules/shortcodes.php). This resolved the problem once and for all.

    I wondered if this was unique to my case, but wanted to ensure to point it out since the next update may break it again and require me to have to re-enter this snippet in the file again. I also hope this little hack isn’t merely plugging a symptomatic hole while a bigger problem lurks elsewhere.

    I hope that helps?..

    Thanks.

    Plugin Author Brandon Kraft

    (@kraftbj)

    Code Wrangler

    I’m not sure what exactly is happening for ya. In the AMP code, it only fires if it is already included (and doesn’t declare it itself, at least the AMP code that we published at Automattic).

    A couple of guesses on my part: 1. Which AMP plugin are you using? or 2. Something else odd with PHP caching is going on (which is a bit of a stretch).

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Resolving Jetpack Conflict with AMP’ is closed to new replies.