什么是add_action(\'init\', \'register_wp_questions\');
在插件中执行。在这个阶段,这是你的问题。您正在将函数挂接到init
这不存在,因此会给您一个错误。
我想您需要注册并将您的CPT挂接到init
钩实际上,您应该将所有代码放在一个函数中,然后将其添加到init
钩您的代码应该是
<?php
/**
* Plugin Name: Name Of The Plugin
* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
* Description: A brief description of the Plugin.
* Version: The Plugin\'s Version Number, e.g.: 1.0
* Author: Name Of The Plugin Author
* Author URI: http://URI_Of_The_Plugin_Author
* License: A "Slug" license name e.g. GPL2
*/
add_action(\'init\', \'register_wp_questions\');
function register_wp_questions() {
$labels = array(
\'name\' => __( \'Questions\', \'wp_question\' ),
\'singular_name\' => __( \'Question\', \'wp_question\' ),
\'add_new\' => __( \'Add New\', \'wp_question\' ),
\'add_new_item\' => __( \'Add New Question\', \'wp_question\' ),
\'edit_item\' => __( \'Edit Questions\', \'wp_question\' ),
\'new_item\' => __( \'New Question\', \'wp_question\' ),
\'view_item\' => __( \'View Question\', \'wp_question\' ),
\'search_items\' => __( \'Search Questions\', \'wp_question\' ),
\'not_found\' => __( \'No Questions found\', \'wp_question\' ),
\'not_found_in_trash\' => __( \'No Questions found in Trash\',\'wp_question\' ),
\'parent_item_colon\' => __( \'Parent Question:\', \'wp_question\'),
\'menu_name\' => __( \'Questions\', \'wp_question\' )
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'description\' => __( \'Questions and Answers\', \'wp_question\' ),
\'supports\' => array( \'title\', \'editor\', \'comments\' ),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => true,
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true,
\'rewrite\' => true,
\'capability_type\' => true
);
register_post_type (\'wp_question\', $args);
}
?>