Error PHP 5.4
-
I am receiving this error, maybe my hosting updated PHP to 5.4 recently…
Warning: Illegal string offset ‘menubar’ in /home4/carlosco/public_html/bajardepeso/wp-content/plugins/tinymce-advanced/tinymce-advanced.php on line 383
-
This error suggests that something is using the
'tiny_mce_before_init'filter improperly. It passes an array, but the error is about it being a string.If you can debug further, could you add a
var_dump( $init );on the first line inTinymce_Advanced::mce_options().Hi Andrew,
I also had some trouble with this in my plugin.
I think it may have been related to PHP 5.4 as well.I ended up adding an if/else check to first see if the array elements were empty or not.
$myMenubar = 'link unlink'; if( empty($init['menubar']) || $init['menubar'] === '') { $init['menubar'] = $myMenubar; } else { $init['menubar'] = $init['menubar'].' '.$myMenubar; }I’m not saying this will work in every case, but I’m 99.98% sure it’s working for me.
It can get a little tricky when working with arrays (you have to know what’s going “in”, to know how to add your customizations).
@josh yeah, that makes sense when you’re appending some settings. You need to check whether the array element is already set.
However in my case it just sets or overrides the previous value:
function mce_options( $init ) { if ( ... ) { $init['menubar'] = true; } return $init; }As far as I see the only way that would throw the above warning is if
$initis a string. However that should never happen as it uses the'tiny_mce_before_init'filter that always passes an array…I can probably add:
if( ! is_array( $init ) ) { $init = array(); }But that will silence the underlying problem which is the improper use of the
'tiny_mce_before_init'filter.I just tested this in my dev site:
1. WP trunk
2. PHP 5.5.9
3. All WP-debug set to true
4. No other plugins
5. Default 2014 themeI could not get any error notice. However, I did note when I added the menubar option; while it did display correctly; I was unable to un-check the option and remove the menubar.
Basically, once I enabled the option, the menubar stayed there until I deactivated the plugin.
Your code is like super-freaking optimized (that’s a good thing); still one or two pay-grades above mine π
But I don’t think the
#init['menubar']will accept a parameter oftrue? I think it either has to be false (disabled) or a string of the layout you would like to use; for example"tools table format view insert edit".Taken from here:
http://www.tinymce.com/wiki.php/Configuration:menubarCould the parameter of
truebe what’s causing the erratic behavior where the menubar can’t removed?@josh it’s a bit more complicated. The
menubarsetting is used in three places: https://github.com/tinymce/tinymce/blob/master/js/tinymce/themes/modern/theme.js#L279 https://github.com/tinymce/tinymce/blob/master/js/tinymce/themes/modern/theme.js#L427 and https://github.com/tinymce/tinymce/blob/master/js/tinymce/themes/modern/theme.js#L503.The first gets the actual menu items if it is a string, the other two just check if it is not
false. So setting it totruewould use the default menu items and enable it.I was unable to un-check the option and remove the menubar.
Hmm, that’s weird. It is a simple checkbox. If you get the time can you add
var_dump( $_POST );at the top and see what’s being submitted when saving the settings. It should be in that array when checked and not in the array when unchecked.You’re right π That makes sense. Thank you for the explanation Andrew. I really appreciate you taking the time to put those links together to show me.
Of course I’ll check the var_dump. Be back shortly.
You’re good, Andrew. It must have been something in my cache. I’m going to make a ‘cache-buster’ for development purposes in TiynMCE π
To clarify (since I took the thread off topic slightly)… I cannot seem to replicate any error notices using PHP 5.5.9 on localhost.
If the OP would like to provide steps to replicate receiving the warning, I’ll be happy to dig further.
Thank you for all your help. It’s working fine.
Andrew, I’ve had the same issue with the tinymce-advanced plugin because my hosting service has done the same thing with the PHP setting.
My PHP setting is 5.4 here and I get the same error from it. If there is a way to correct this in the WP dashboard in the editing error, how I do this? The plugin is currently deactivated because of this issue. Could you or someone please tell me how to fix this issue? Because the hosting provider PHP setting in the server is PHP 5.4 and that is what is causing the issue as previously mentioned above and in the previous post to this thread. Please respond soon. P.S If you did fix this problem, how did you do it as I would like to know? Please fill me in tell me if there is anything I need to do from my end.Josh, Thank You as well also.
The topic ‘Error PHP 5.4’ is closed to new replies.