2016-08-04 54 views
1

我有一个公共职能附加分类法自定义帖子类型。当调试设置为true时,我在Wordpress中获取此错误代码:WordPress的add_action未定义偏移0在plugin.php行925和943

Notice: Undefined offset: 0 in C:\xampp\htdocs\yanjep-dev\wp-includes\plugin.php on line 925 
Notice: Undefined offset: 0 in C:\xampp\htdocs\yanjep-dev\wp-includes\plugin.php on line 943 

这样每个重复9次。

我已经分离出的问题在这里的ADD_ACTION功能:

add_action('init', 
       call_user_func_array('register_taxonomy', array($taxonomy_name, $post_type_name, $args)) 
      ); 

整个功能是在这里:使用XAMPP

public function add_taxonomy($name, $args = array(), $labels = array()) 
{ 
    if(! empty($name)) 
    {   
     // We need to know the post type name, so the new taxonomy can be attached to it. 
     $post_type_name = $this->post_type_name; 

     // Taxonomy properties 
     $taxonomy_name  = strtolower(str_replace(' ', '_', $name)); 
     $taxonomy_labels = $labels; 
     $taxonomy_args  = $args; 

     if(! taxonomy_exists($taxonomy_name)) 
     { 
      //Capitilize the words and make it plural 
      $name  = ucwords(str_replace('_', ' ', $name)); 
      $plural  = $name . 's'; 

      // Default labels, overwrite them with the given labels. 
      $labels = array_merge(

       // Default 
       array(
        'name'     => _x($plural, 'taxonomy general name'), 
        'singular_name'   => _x($name, 'taxonomy singular name'), 
        'search_items'   => __('Search ' . $plural), 
        'all_items'    => __('All ' . $plural), 
        'parent_item'   => __('Parent ' . $name), 
        'parent_item_colon'  => __('Parent ' . $name . ':'), 
        'edit_item'    => __('Edit ' . $name), 
        'update_item'   => __('Update ' . $name), 
        'add_new_item'   => __('Add New ' . $name), 
        'new_item_name'   => __('New ' . $name . ' Name'), 
        'menu_name'    => __($name), 
       ), 

       // Given labels 
       $taxonomy_labels 

      ); 

      // Default arguments, overwitten with the given arguments 
      $args = array_merge(

       // Default 
       array(
        'label'     => $plural, 
        'labels'    => $labels, 
        'public'    => true, 
        'show_ui'    => true, 
        'show_in_nav_menus'  => true, 
        '_builtin'    => false, 
       ), 

       // Given 
       $taxonomy_args 

      ); 

      // Add the taxonomy to the post type 
      add_action('init', 
       call_user_func_array('register_taxonomy', array($taxonomy_name, $post_type_name, $args)) 
      ); 
     } 
     else 
     {    
      add_action('init', array($this, 'add_taxonomy_to_post_type')); 
     } 
    } 
} 

我在本地工作。如果我评论这一行动,通知消失。我知道这与争论的数量有关,但我无法解决它。

任何帮助表示赞赏。

回答

0

如你所知,ADD_ACTION需要两个参数:过滤器(register_taxonomyfunction name调用

据我所知,add_action需要引用实际的功能,你不能在一个call_user_func_array呼叫传递如果你跟踪。在WP中的代码中,你会看到add_action依次调用add_filter,后者又调用_wp_filter_build_unique_id,这就是抛出错误的位置。如果调查该代码,则会看到它预计会出现一个字符串 - 如函数名称(例如register_my_taxonomy),或者用于类方法的数组(例如:遵循PHP标准方式)。例如:

add_action('init', 'register_my_taxonomy'); // Call a standard function 
add_action('init', array($this, 'register_my_taxonomy'); // call a public class method 
add_action('init', array(__CLASS__, 'register_my_taxonomy'); // call a public static method 

下去,因为它似乎你是在一个类时,你的电话add_action('init'...),我建议将其更改为引用类功能:

 add_action('init', 
      array($this, 'register_my_taxonomy') 
     ); 

而且在你的类,创建函数register_my_taxonomy其中在您的分类标准上循环并直接调用register_taxonomy