[wp-trac] [WordPress Trac] #45192: WP_DEBUG notice when classic editor is forced and static methods used causes fatal errors.

WordPress Trac noreply at wordpress.org
Thu Oct 25 20:28:03 UTC 2018


#45192: WP_DEBUG notice when classic editor is forced and static methods used
causes fatal errors.
--------------------------+------------------------------
 Reporter:  claudiulodro  |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Editor        |     Version:  5.0
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:  administration
--------------------------+------------------------------
Changes (by DrewAPicture):

 * keywords:   => needs-patch
 * focuses:   => administration
 * component:  General => Editor


Comment:

 It's important to note that the [https://wordpress.org/support/topic
 /fatal-errors-on-metaboxes-with-classic-editor-when-wp_debug-is-true/
 original report] in Alpha/Beta cited a WooCommerce metabox registration as
 the code triggering the fatal. This is important context because
 WooCommerce is referencing the callback as a string-based static method
 call:

 {{{
 #!php
 add_meta_box( 'woocommerce-product-images', __( 'Product gallery',
 'woocommerce' ), 'WC_Meta_Box_Product_Images::output', 'product', 'side',
 'low' );
 }}}

 With that context in mind, the `is_array()` check intended to capture
 method calls is understandably failing and the fatal is thrown when
 `ReflectionFunction()` doesn't know what to do with it.

 It feels a bit icky, but I guess we could do an elseif checking for `::`
 in the callback string before falling back to `ReflectionFunction()` in
 the else.


 Here is the core code in question::

 {{{
 #!php
 if ( WP_DEBUG && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-
 loader'] ) ) {
         if ( is_array( $box['callback'] ) ) {
                 $reflection = new ReflectionMethod( $box['callback'][0],
 $box['callback'][1] );
         } else {
                 $reflection = new ReflectionFunction( $box['callback'] );
         }

         // Don't show an error if it's an internal PHP function.
         if ( ! $reflection->isInternal() ) {

                 // Only show errors if the meta box was registered by a
 plugin.
                 $filename = $reflection->getFileName();
                 if ( strpos( $filename, WP_PLUGIN_DIR ) === 0 ) {
                         $filename = str_replace( WP_PLUGIN_DIR, '',
 $filename );
                         $filename = preg_replace( '|^/([^/]*/).*$|',
 '\\1', $filename );

                         $plugins = get_plugins();
                         foreach ( $plugins as $name => $plugin ) {
                                 if ( strpos( $name, $filename ) === 0 ) {
                                         ?>
                                                 <div class="error inline">
                                                         <p>
                                                                 <?php
                                                                         /*
 translators: %s: the name of the plugin that generated this meta box. */
 printf( __( "This meta box, from the %s plugin, isn't compatible with the
 block editor." ), "<strong>{$plugin['Name']}</strong>" );
                                                                 ?>
                                                         </p>
                                                 </div>
                                         <?php
                                 }
                         }
                 }
         }
 }

 call_user_func($box['callback'], $object, $box);
 }}}

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


More information about the wp-trac mailing list