• Hi,

    Do you plan on updating your code for Php7.0? I found just this one error when checking compatability:

    FILE: /nas/content/live/genroe/wp-content/plugins/shortcodes-ultimate/inc/core/tools.php
    ————————————————————————————————————————-
    FOUND 1 ERROR AFFECTING 1 LINE
    ————————————————————————————————————————-
    681 | ERROR | Using ‘break’ outside of a loop or switch structure is invalid and will throw a fatal error since PHP 7.0
    ————————————————————————————————————————-

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hey Adam!

    I am not the developer, but I ran into this compatibility issue, as well, so I decided to look at the plugin code to try and see what was actually causing the issue.

    What I found is that the error you mentioned above is being thrown because there is a foreach loop (starting on line 675, ending 682) which uses implicit braces, meaning that the developer chose to not include the “{}” characters around the loop. Because the scanning plugin did not find those braces wrapping around the code block for that loop, it thinks that the “break” statement is outside of a loop, but it actually isn’t.

    The Fix
    I tested this fix out and it no longer throws the compatibility error; if you are comfortable with editing the PHP code, just add explicit braces around the loop block:

    So, this:

    foreach ( array( 'media', 'posts', 'category', 'taxonomy' ) as $type )
    	if ( strpos( trim( $args['source'] ), $type . ':' ) === 0 ) {
    		$args['source'] = array(
    			'type' => $type,
    			'val'  => (string) trim( str_replace( array( $type . ':', ' ' ), '', $args['source'] ), ',' )
    		);
    		break;
    	}

    becomes this:

    foreach ( array( 'media', 'posts', 'category', 'taxonomy' ) as $type )
    {
    	if ( strpos( trim( $args['source'] ), $type . ':' ) === 0 ) {
    		$args['source'] = array(
    			'type' => $type,
    			'val'  => (string) trim( str_replace( array( $type . ':', ' ' ), '', $args['source'] ), ',' )
    		);
    		break;
    	}
    }

    The file you will need to edit is “/wp-content/plugins/shortcodes-ultimate/inc/core/tools.php”

    – Joe

    Hey Adam!

    I am not the developer, but I ran into the same compatibility issue that you mentioned above, so I decided to look into the code and find out what is actually causing the error to be thrown.

    What I found was that there is a foreach loop (starting line 675, ending line 682) for which the developer used implicit braces, meaning that they chose not include the “{}” characters around the loop code block. Since the scanning plugin did not find those braces, it thinks that the “break” statement is outside of a loop block, which it actually isn’t. I have tested out a fix for this, that has resolved the compatibility error on my sites.

    The Fix
    If you are comfortable with editing the PHP code of the plugin, you just need to add explicit braces around the offending loop block.

    So this:

    foreach ( array( 'media', 'posts', 'category', 'taxonomy' ) as $type )
    	if ( strpos( trim( $args['source'] ), $type . ':' ) === 0 ) {
    		$args['source'] = array(
    			'type' => $type,
    			'val'  => (string) trim( str_replace( array( $type . ':', ' ' ), '', $args['source'] ), ',' )
    		);
    		break;
    	}

    becomes this:

    
    foreach ( array( 'media', 'posts', 'category', 'taxonomy' ) as $type )
    {
    	if ( strpos( trim( $args['source'] ), $type . ':' ) === 0 ) {
    		$args['source'] = array(
    			'type' => $type,
    			'val'  => (string) trim( str_replace( array( $type . ':', ' ' ), '', $args['source'] ), ',' )
    		);
    		break;
    	}
    }

    The file that you need to update is “wp-content/plugins/shortcodes-ultimate/inc/core/tools.php”.

    • This reply was modified 7 years, 8 months ago by Joe Brodar. Reason: fixing code blocks
    Thread Starter Adam Ramshaw

    (@aramshaw)

    Joe,

    Thanks for letting me know about the fix – nice investigation.

    If I understand you the old code would work with PHP7 as well. The problem is with the compatibility scanner.

    I’m comfortable making the change but my concern was that the fix will break with the next of the plugin update — but if both work under PHP7 the it doesn’t matter.

    Adam

    Adam,

    You are correct, it is really just an issue with the scanner, not actually the plugin itself, so it should work on PHP7 without applying the fix, but I have not tested that to say for sure.

    Hopefully, if the developer does update again, they will add the explicit braces so that it doesn’t continue to throw up the false flag!

    – Joe

    Joe Brodar! Awesome Fix! Thank you SO much for posting that here.

    I’ve run the PHP compatibility checker against this plugin and PHP 7 and there are no errors.

    Sweet!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Support for Php 7.0’ is closed to new replies.