-1
我想回收自定義帖子類型wordpress函數和add_action鉤子。不過,我不斷收到我的函數「cpt_function_name」缺少的參數。在這段代碼的底部,我嘗試傳遞實例化時需要傳遞給類的參數。幫幫我?在PHP類中爲函數傳遞外部參數
class classCPT
{
public $singular;
public $plural;
public $cpt_name;
public $cpt_icon;
public function __construct() {
add_action('admin_init', array($this, cpt_function_name));
}
public function cpt_function_name($singular, $plural, $cpt_name, $cpt_icon) {
$labels = array(
'name' => $plural,
'singular_name' => $singular,
'add_name' => 'Add New',
'add_new_item' => 'Add New ' . $singular,
'edit' => 'Edit',
'edit_item' => 'Edit ' . $singular,
'new_item' => 'New ' . $singular,
'view' => 'View ' . $singular,
'view_item' => 'View ' . $singular,
'search_term' => 'Search ' . $singular,
'parent' => 'Parent ' . $singular,
'not_found' => 'No ' . $plural . ' found',
'not_found_in_trash' => 'No ' . $plural . ' in Trash',
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true, //part of WP query
'exclude_from_search' => false,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 20,
'menu_icon' => $cpt_icon,
'can_export' => true,
'delete_with_user' => false,
'hierarchical' => false,
'has_archive' => true,
'query_var' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
'taxonomies' => array(''),
'rewrite' =>array('slug' => $cpt_name, 'with_front' => true, 'pages' => true, 'feeds' => true,),
'supports' =>array('title', 'editor', 'thumbnail',),
);
register_post_type($cpt_name , $args);
}
}
$newCPT = new classCPT('Safari', 'Safaris', 'safaris', 'dashicons-palmtree');
我想這是'陣列($此, 'cpt_function_name')',用引號。 –
是。對不起,:)更新了答案 –