Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#35693 closed defect (bug) (invalid)

PHP Warning: implode(): Invalid arguments passed in wp-includes/class-wp-editor.php on line 683

Reported by: aohipa Owned by:
Priority: normal Milestone:
Component: Editor Version: 4.4.1
Severity: normal Keywords:
Cc: Focuses:

Description

Everytime we use a WYSIWYG editor we get this PHP warning.
NULL values are beeing used to fill the toolbar1/2/3/4 attributes in $mceInit.
And souldn't it be implode(',', $mce_buttons) and so on? Seems like $glue and $pieses are mixed up...

proposal:

<?php
$mceInit = array (
        'selector' => "#$editor_id",
        'resize' => 'vertical',
        'menubar' => false,
        'wpautop' => (bool) $set['wpautop'],
        'indent' => ! $set['wpautop'],
        'toolbar1' => ($mce_buttons)?   implode(',', $mce_buttons)   : NULL,
        'toolbar2' => ($mce_buttons_2)? implode(',', $mce_buttons_2) : NULL,
        'toolbar3' => ($mce_buttons_3)? implode(',', $mce_buttons_3) : NULL,
        'toolbar4' => ($mce_buttons_4)? implode(',', $mce_buttons_4) : NULL,
        'tabfocus_elements' => $set['tabfocus_elements'],
        'body_class' => $body_class
);

Change History (4)

#1 @azaozz
11 years ago

  • Milestone Awaiting Review
  • Resolution → invalid
  • Status new → closed

It seems you are using one or more of the mce_buttons, mce_buttons_2, mce_buttons_3, etc. filters. They pass an array and expect an array back. If you're returning anything else than array, you're using them improperly. Keep in mind that another plugin can be using the same filter after you and is expecting an array too.

#2 follow-up: @aohipa
11 years ago

  • Resolution invalid
  • Status closed → reopened

@azaozz Thanks for the quick answer, but I don't think I use it incorrectly.
That's what my filter looks like:

<?php
add_filter('mce_buttons', function ($aButtons) {
        return [
                'styleselect',
                'bold',
                'italic',
                'underline',
                'strikethrough',
                'bullist',
                'numlist',
                'alignleft',
                'aligncenter',
                'alignright',
                'hr',
                'outdent',
                'indent',
                'link',
                'unlink',
                'pastetext',
                'removeformat',
                'charmap',
                'undo',
                'redo'
        ];
});

I did not want to merge a new array with the existing buttons array and rearrange it's items to get the result I want, so I just returned an array with the right order. I dont use plugins, that change the MCE configuration either.

The filter seems to work just fine and I can see that by looking at the backend. The buttons are there and in the correct order. But I still get this warning, everytime wp_editor is executed because anywhere along the way the buttons array has been NULL and therefore is not a acceptable parameter for implode().

And even if I was using it wrong, wouldn't it be good to check the input for implode before using it?

EDIT: Btw.: The problem remains, even when I remove my usages of the filter.

Last edited 11 years ago by aohipa (previous) (diff)

#3 in reply to: ↑ 2 ; follow-up: @azaozz
11 years ago

Replying to aohipa:

@azaozz Thanks for the quick answer, but I don't think I use it incorrectly.

Right, as long as you return an array, it is the correct use.

And even if I was using it wrong, wouldn't it be good to check the input for implode before using it?

No, because if there are two or more plugins using the same filter, the second would expect an array. All plugins using a filter will have to respect the parameter type. If they don't we need to warn the authors they are "doing it wrong" :)

EDIT: Btw.: The problem remains, even when I remove my usages of the filter.

Is there perhaps another plugin using one of these filters?

Version 0, edited 11 years ago by azaozz (next)

#4 in reply to: ↑ 3 @aohipa
11 years ago

  • Resolution → invalid
  • Status reopened → closed

Replying to azaozz:

Is there perhaps another plugin using one of these filters?

Ah, there was another plugin... it used the filter but commented out everything inside the function. Maybe some leftover development code that wasn't correctly removed. Thanks again!

Note: See TracTickets for help on using tickets.