[wp-trac] [WordPress Trac] #51729: "Uncaught TypeError: is_file(): Argument #1 ($filename) must be of type string, array given" when using the 'mce_external_languages' filter

WordPress Trac noreply at wordpress.org
Mon Nov 9 04:58:30 UTC 2020


#51729: "Uncaught TypeError: is_file(): Argument #1 ($filename) must be of type
string, array given" when using the 'mce_external_languages' filter
--------------------------+----------------------
 Reporter:  BackuPs       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Editor        |     Version:
 Severity:  normal        |  Resolution:  invalid
 Keywords:  php8          |     Focuses:
--------------------------+----------------------
Changes (by jrf):

 * status:  new => closed
 * version:  trunk =>
 * resolution:   => invalid
 * milestone:  5.6 =>


Comment:

 @BackuPs Thanks for reporting this, but this is not a WP core bug, but a
 bug in your own code.

 As per the documentation for the `mce_external_languages` filter:

 > The filter takes an associative array `('plugin_name' => 'path')` where
 `'path'` is the include path to the file.

 That is, however, not what your code is doing. You are returning a non-
 associative array with an associative array as the value of `path`.

 {{{#!php
 <?php
 function add_tinymce_languages($langs){
         $langs[] = array('shortcodeGenerator' =>
 THEME_ADMIN.'/shortcodes/langs/langs.php');
         return $langs;
 }
 }}}


 While this code would not throw an error on PHP < 8, it should also not
 work.

 Try replacing your code with this:
 {{{#!php
 <?php
 function add_tinymce_languages($langs){
         $langs['shortcodeGenerator'] =
 THEME_ADMIN.'/shortcodes/langs/langs.php';
         return $langs;
 }
 }}}

 That should fix your bug and prevent the error on PHP 8.

 And while you are at it, you may also want to replace the hook-in to not
 pass `$this` by reference. Objects are always passed by reference in PHP
 5+, so the reference is unnecessary.
 {{{#!php
 <?php
 add_filter('mce_external_languages', array($this,
 'add_tinymce_languages'));
 }}}


 > but the same code should emit a warning; I presume that warning was
 silenced from error handler or PHP settings.

 @ayeshrajans The relevant line in WP Core handling the output of the
 filter uses error silencing, so the bug would have been silently ignored
 prior to PHP 8.

 File `wp-includes/class-wp-editor.php:489`:
 {{{#!php
 <?php
 if ( @is_file( $path ) && @is_readable( $path ) ) {
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51729#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list