0

Could anybody help me on this please? Happend after updating to PHP 7.73 (stable) and updating theme as well as the plugins.

/**
     * Get single meta box by name
     *
     * @param int    $post_id
     * @param string $control_name valid meta box name
     * @param bool   $remove_first remove first element
     *
     * @return array|boolean
     *
     * @access   public
     */
    public function get( $post_id, $control_name, $remove_first = true ) {
        $post_meta = get_post_meta( $post_id, $this->getId(), true );

        if ( $post_meta && RecursiveArray::searchKey( $control_name, $post_meta ) ) {

            $meta_boxes = RecursiveArray::searchRecursive( $post_meta, $control_name );

            if ( \count( $meta_boxes ) == 1 && \is_array( $meta_boxes ) && $remove_first ) {
                return $meta_boxes[ 0 ];
            }

            if ( is_array( $meta_boxes ) ) {
                $meta_boxes = RecursiveArray::removeEmpty( $meta_boxes );
            }

            return $meta_boxes;

        } else {
            return false;
        }
    }

Warning: count(): Parameter must be an array or an object that implements Countable in...

Error is within these lines:

if ( \count( $meta_boxes ) == 1 && \is_array( $meta_boxes ) && $remove_first ) {
                return $meta_boxes[ 0 ];
            }

How can I correct this so that I don't get this error? Is it something with the closing parenthesis?

Noob2013
  • 27
  • 1
  • 6

1 Answers1

1

You can try to invert count( $meta_boxes ) and is_array( $meta_boxes ) :

 if (  \is_array( $meta_boxes ) && \count( $meta_boxes ) == 1 && $remove_first ) {
             return $meta_boxes[ 0 ];
        }

if $meta_boxes is not an array the 1st condition will not be ok and count won't be tested

R. Martin
  • 411
  • 2
  • 11