我是wordpress的新手,并且内置了一个虚拟插件,以查看wordpress自定义插件如何工作。出于某种原因,当我激活它时,我在侧边栏中看不到插件名称吗?我已经查看了我的代码几次,似乎无法找出问题所在。如果有人知道我在这里做错了,我将不胜感激!!!
下面是我的代码
<?php
/*Plugin Name: Custom Cpt */
class Cpt {
public function __construct()
{
add_action("registerPostType",[$this,"Cpt"]);
}
function registerPostType(){
$labels = [
"name"=> __("Products"),
"singular_name" => __("Product"),
"edit_name" => "Edit Products",
"new_item" => "New Products",
"view_item"=>"View products",
"menu_name" => "Products",
"name_admin_bar"=> "Products"
];
$args = [
"labels" => $labels,
"has_archive" => true,
"public" => true,
"show_in_menu"=>true,
"show_in_admin_bar"=>true,
"menu_icon" => "dashicons-admin-multisite",
"hierarchical"=> true,
];
register_post_type("custom_post",$args);
}
}
new Cpt();
用这个
add_action('init',[$this,'registerPostType'] );
如果不在构造函数中。用
add_action('init','registerPostType' );
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句