插件自定义开机自检类型-内部服务器错误

时间:2014-04-29 作者:user47126

我需要在wordpress 3.9中为自定义帖子类型创建一个插件。当我激活插件时,我收到一个内部服务器错误500。此外,插件未在管理仪表板中列出。这是我的代码:

<?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\');

$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);

?>
请帮忙。我怎样才能找出错误呢?

谢谢

1 个回复
最合适的回答,由SO网友:Pieter Goosen 整理而成

什么是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);

}

?>

结束

相关推荐

为什么不调用/触发“Plugins_Load”?

我正在打电话load_plugin_textdomain 然而,一旦加载了插件,就不会发生这种情况。我确实激活了一个插件,所以这不应该触发吗?add_action(\"plugins_loaded\", \"test_override\"); function init_localization() { echo \"init_localization<br>\"; load_plugin_textdomain (&#x