2016-08-04 1 views
1

私はカスタムの投稿タイプにタクソノミを添付するパブリック関数を持っています。デバッグがtrueに設定されている場合、Wordpressでこのエラーコードが表示されます。Wordpress add_action plugin.phpのオフセット0を定義していません。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)) 
      ); 

関数全体はここにある:

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')); 
     } 
    } 
} 

私はXAMPPを使用してローカルで働いています。私がその行動をコメントアウトすると、通知が消えます。私はそれが議論の数と何かを持っていることを知っていますが、私はそれを解決することはできません。

何か助けていただければ幸いです。

答えて

0

ご存知のように、add_actionは2つの引数が必要です:フィルタ(register_taxonomy、およびfunction nameは、呼び出すために、実際の関数を参照する必要があり、あなたがcall_user_func_arrayコールに渡すことはできませんadd_action

私の知る限りを、あなたトレースした場合。 WPのコードでは、add_actionadd_filterを呼び出し、エラーがスローされている_wp_filter_build_unique_idを呼び出していることがわかります。そのコードを調べると、関数名(例えばregister_my_taxonomy)、またはクラスメソッドの配列(PHPの標準的な方法に従う)。例:

関数を作成し、

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

そして、あなたのクラスの:それはあなたがあなたのadd_action('init'...)呼び出しで、クラスで作業している表示されますので、

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 

ので、私はそれがクラスの関数を参照するように変更することをお勧めしたいですregister_my_taxonomyはタクソノミーに戻り、register_taxonomyを直接呼び出します。

関連する問題