• I have several notices with php7.4. I am using version 1.0.0.

    Trying to access array offset on value of type bool.

    wp-content/plugins/tabify-edit-screen/inc/edit-screen.php:181
    wp-content/plugins/tabify-edit-screen/inc/edit-screen.php:182

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author CodeKitchen

    (@codekitchen)

    What plugins are you using and what is the version of WordPress? Seems something is changing WordPress internals.

    Thread Starter Remco

    (@rembem)

    I tracked down the cause: I have several places where I remove unwanted metaboxes added by plugins etc. with a remove_meta_box() function:
    – in my functions.php
    – in a plugin I use: https://www.ads-software.com/plugins/radio-buttons-for-taxonomies/
    which removes and adds metaboxes.

    I noticed your function get_meta_boxes() is called by show_tabs() runs on the admin_menu hook with priority 100.
    The PHP notices are present when metaboxes are apparently removed before your plugin function runs.
    When I let my function run on the same hook with a later priority, there are no notices.
    For the other plugin (Radio Buttons for Taxonomies), coincidentally I am in contact with the author of it, for some code improvements, so I might be able to get that plugin to run later also.

    However, I think it might be a good idea that Tabify Edit Screen takes into account that metaboxes might have been removed prior to it running, and a metabox array might be returning false in your get_meta_boxes() function.So that even when metaboxes are removed, php7.4 does not give notices.

    Edit:
    I just realised that the byproduct of letting remove_meta_box() functions run AFTER Tabify Edit Screen, is that they show up in the Tabify Edit Screens settings page, where you can move them around. This is not optimal for users and confusing. And in the case of the RadioButtonsForTaxonomies plugin, it is even more confusing, because that plugin replaces a metabox by removing it, then adding a new one. When that plugin runs AFTER Tabify Edit Screen, these metaboxes show up double in the TabifyEditScreen settings. So it would be better that Tabify Edit Screens functions account for metaboxes that have been removed before it.

    • This reply was modified 3 years, 8 months ago by Remco.
    • This reply was modified 3 years, 8 months ago by Remco.
    Thread Starter Remco

    (@rembem)

    Update: this seems solved, now the author of the RadioButtonsForTaxonomies plugin has rewritten part of the plugin that adds and remove meta boxes.

    Hi all… I’m the author of Radio Buttons for Taxonomies and I was just seeing the same issue of notices. I’m seeing it with just Tabify and WooCommerce enabled when editing a product post.

    
    Notice: Trying to access array offset on value of type bool in wp-content\plugins\tabify-edit-screen\inc\edit-screen.php on line 183
    Call Stack
    #	Time	Memory	Function	Location
    1	0.0004	371672	{main}( )	...\post.php:0
    2	1.4260	8962112	require( 'wp-admin\edit-form-advanced.php' )	...\post.php:206
    3	1.5369	9084376	require_once( 'wp-admin\admin-header.php' )	...\edit-form-advanced.php:425
    4	1.6327	9231912	do_action( )	...\admin-header.php:147
    5	1.6327	9232288	WP_Hook->do_action( )	...\plugin.php:484
    6	1.6327	9232288	WP_Hook->apply_filters( )	...\class-wp-hook.php:316
    7	1.6361	9232696	Tabify_Edit_Screen_Edit_Screen->show_tabs( )	...\class-wp-hook.php:292
    8	1.6372	9256608	Tabify_Edit_Screen_Edit_Screen->get_meta_boxes( )	...\edit-screen.php:74
    

    The var dump for $this->all_metaboxes = $this->get_meta_boxes( $post_type ); on a WooCommerce product screen is:

    
    
    array (size=10)
      'product_catdiv' => string 'product_catdiv' (length=14)
      'tagsdiv-product_tag' => string 'tagsdiv-product_tag' (length=19)
      '' => null
      'postimagediv' => string 'postimagediv' (length=12)
      'woocommerce-product-images' => string 'woocommerce-product-images' (length=26)
      'postcustom' => string 'postcustom' (length=10)
      'slugdiv' => string 'slugdiv' (length=7)
      'woocommerce-product-data' => string 'woocommerce-product-data' (length=24)
      'postexcerpt' => string 'postexcerpt' (length=11)
      'commentsdiv' => string 'commentsdiv' (length=11)
    

    I’m not sure what the ''=>null is from, but that’s what is throwing the notice I think.

    And it can probably be resolved by checking if each $metabox is an array and if not skipping it.

    
    /**
     * Get meta boxes from a post type
     *
     * @param string $post_type Post type name
     *
     * @return array $metaboxes List of metaboxes
     *
     * @since 1.0.0
     */
    private function get_meta_boxes( $post_type ) {
    	global $wp_meta_boxes;
    
    	$metaboxes         = array();
    	$default_metaboxes = $this->get_default_items( $post_type );
    
    	foreach ( $wp_meta_boxes[ $post_type ] as $priorities ) {
    		foreach ( $priorities as $priority => $_metaboxes ) {
    			foreach ( $_metaboxes as $metabox ) {
    				if ( ! is_array( $metabox ) ) {
    					continue;
    				}
    				if ( ! in_array( $metabox['id'], $default_metaboxes ) ) {
    					$metaboxes[ $metabox['id'] ] = $metabox['id'];
    				}
    			}
    		}
    	}
    
    	return $metaboxes;
    }
    
    Thread Starter Remco

    (@rembem)

    My previous remark about this being solved was premature. See reply above from. I have this too, and the proposed solution fixes it.

    I believe the ''=>null is coming from metaboxes that have been removed by user functions and plugins.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Notices in php7.4’ is closed to new replies.