我有以下代码来生成自定义post类型对象:
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;
在类的后面,我有一个方法,该方法生成带有一些默认值的标签,然后允许在创建类的新实例时传入重写。
// 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
);
在WordPress中查看调试日志时,我发现出现了一个错误,参数#2,
$this->post_type_labels
不是数组,即使在创建过程中省略了它,默认情况下也会传入一个空数组。
如何清除此警告并确保$this->post_type_labels
是数组吗?我没有收到同样的信息$args