0

I have the following code to generate a custom post type object:

public function __construct( $name, $args = array(), $labels = array() ) {

    // Set Variables
    $this->post_type_name      = self::uglify( $name );
    $this->post_type_args      = $args;
    $this->post_type_lables    = $labels;

Later in in the class, I have a method that generates the labels with some defaults and then allows overrides to be passed in when a new instance of the class is created.

// Set labels with some defaults and merge in overrides
$labels = array_merge(

    // Default values
    array(
        'name'               => _x( $plural, 'Post Type General Name' ),
        'singular_name'      => _x( $name, 'Post Type Singular Name' ),
        'add_new'            => _x( 'Add New ', strtolower( $name ) ),
        'add_new_item'       => __( 'Add New ' . $name ),
        'edit_item'          => __( 'Edit ' . $name ),
        'new_item'           => __( 'New ' . $name ),
        'all_items'          => __( 'All ' . $plural ),
        'view_item'          => __( 'View ' . $name ),
        'search_items'       => __( 'Search ', $plural ),
        'not_found'          => __( 'No ' . strtolower( $plural ) . ' found' ),
        'not_found_in_trash' => __( 'No ' . strtolower( $plural ) . ' found in Trash' ),
        'parent_item_colon'  => '',
        'menu_name'          => $plural
    ),

    // Overrides
    $this->post_type_labels
);

While looking at the debug log in WordPress, I saw I was getting an error that Arguement #2, $this->post_type_labels was not an array even though if it is omitted in the creation, an empty array is passed in by default.

How do I clear this warning and make sure $this->post_type_labels is an array? I am NOT getting the same message with $args

1

You have a typo in line:

$this->post_type_lables    = $labels;

then, you use undeclared variable $this->post_type_labels as a second argument of array_merge function.

  • Ugh... I need to stop coding when the caffeine runs out... Thanks for the extra pair of eyes. – Cedon Nov 17 '17 at 5:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.