Joe Brodar
Forum Replies Created
-
Forum: Plugins
In reply to: [WP Shortcodes Plugin — Shortcodes Ultimate] Support for Php 7.0Adam,
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
Forum: Plugins
In reply to: [WP Shortcodes Plugin — Shortcodes Ultimate] PHP7 ErrorI 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”.
Forum: Plugins
In reply to: [WP Shortcodes Plugin — Shortcodes Ultimate] Support for Php 7.0Hey 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
Forum: Plugins
In reply to: [WP Shortcodes Plugin — Shortcodes Ultimate] Support for Php 7.0Hey 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