Support » Plugin: Shortcodes Ultimate » PHP7 Error

  • I’m looking to move up to PHP7. After completing a scan I got the following error and I’m wondering if there are plans to get this plugin ready for 7.

    FILE:/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 6 replies - 1 through 6 (of 6 total)
  • Same here. 681 | ERROR | Using ‘break’ outside of a loop or switch structure is invalid and will throw a fatal error since PHP 7.0 Can someone help about this issue?
    Thank you,

    Lobsang

    • This reply was modified 2 years, 4 months ago by  YoWangdu.

    I’m getting the same error – would love to get this fixed asap.

    • This reply was modified 2 years, 4 months ago by  Millermore.

    I posted this in another support thread as well:

    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”.

    Thanks Joe for sharing the solution. I hope Vladimir or MadFork will update the plugin. So when there is plugin updates, we don’t have to worry about the over writing code.

    Thank you,

    Lobsang

    This is great Joe! Thanks!

    Does not work for my site. If I copy paste code above, an error appears:

    Parse error: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) or const (T_CONST) in /home/***/wp-content/plugins/shortcodes-ultimate/inc/core/tools.php on line 687

    Please, update this plugin. With PHP 5.6 my site runs very slow…

    • This reply was modified 1 year, 11 months ago by  dzembak.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘PHP7 Error’ is closed to new replies.