我正在创建一个插件,创建一个我正在处理的自定义帖子类型。我跟着this tutorial. 我刚刚将其从movie\\u reviews更改为员工。我在PHP中没有发现任何语法错误,看起来一切正常,但当我在WordPress中激活插件时,它说它生成了3个字符的意外输出。我认为问题在于display\\u staff\\u member\\u meta\\u box函数,但它似乎没有任何错误。下面是我正在使用的代码。
<?php
/*
Plugin Name: Staff Members
Plugin URI: http://intranet.yourgroupuk.com
Description: Declares a plugin that will create a custom post type displaying staff members
Version: 1.0
Author: Harry Glozier
Author URI: http://intranet.yourgroupuk.com
*/
function create_staff_member() {
register_post_type( \'staff_members\',
array(
\'labels\' => array(
\'name\' => \'Staff Members\',
\'singular_name\' => \'Staff Member\',
\'add_new\' => \'Add New\',
\'add_new_item\' => \'Add New Staff Member\',
\'edit\' => \'Edit\',
\'edit_item\' => \'Edit Staff Member\',
\'new_item\' => \'New Staff Member\',
\'view\' => \'View\',
\'view_item\' => \'View Staff Member\',
\'search_items\' => \'Search Staff Members\',
\'not_found\' => \'Staff Member not found\',
\'not_found_in_trash\' => \'No Staff Members found in Trash\',
\'parent\' => \'Parent Staff Member\'
),
\'public\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 80,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'revisions\' ),
\'menu_icon\' => plugins_url( \'staff-icon-2.png\', __FILE__ ),
\'exclude_from_search\' => false,
\'has_archive\' => true
)
);
}
function my_admin() {
add_meta_box( \'staff_member_meta_box\',
\'Staff Member Details\',
\'display_staff_member_meta_box\',
\'staff_members\', \'normal\', \'high\'
);
}
?>
<?php
function display_staff_member_meta_box( $staff_member ) { //Causes error
// Retrieve current Job Title and Company based on staff ID
$job_title = esc_html( get_post_meta( $staff_member->ID, \'job_title\', true ) );
$company = esc_html( get_post_meta( $staff_member->ID, \'company\', true ) );
$table = <<<TEXT
<table>
<tr>
<td style="width: 100%">Job Title</td>
<td><input type="text" size="80" name="staff_member_job_title" value="$job_title" /></td>
</tr>
<tr>
<td style="width: 150px">Company</td>
<td>
<select style="width: 200px" name="staff_member_company">
<option value="Your Group">Your Group</option>
<option value="Your Power">Your Power</option>
<option value="Your Electrical">Your Electrical</option>
<option value="Newmills Engineering">Newmills Engineering</option>
</select>
</td>
</tr>
</table>
TEXT;
echo $table;
} //End of function
?>
<?php
function add_staff_member_fields( $staff_member_id, $staff_member ) {
// Check post type for staff members
if ( $staff_member->post_type == \'staff_members\' ) {
// Store data in post meta table if present in post data
if ( isset( $_POST[\'staff_member_job_title\'] ) && $_POST[\'staff_member_job_title\'] != \'\' ) {
update_post_meta( $staff_member_id, \'job_title\', $_POST[\'staff_member_job_title\'] );
}
if ( isset( $_POST[\'staff_member_company\'] ) && $_POST[\'staff_member_company\'] != \'\' ) {
update_post_meta( $staff_member_id, \'company\', $_POST[\'staff_member_company\'] );
}
}
}
/* function include_template_function( $template_path ) {
if ( get_post_type() == \'staff_members\' ) {
if ( is_single() ) {
// checks if the file exists in the theme first,
// otherwise serve the file from the plugin
if ( $theme_file = locate_template( array ( \'single-staff_members.php\' ) ) ) {
$template_path = $theme_file;
} else {
$template_path = plugin_dir_path( __FILE__ ) . \'/single-staff_members.php\';
}
}
}
return $template_path;
} */
?>
<?php
add_action( \'init\', \'create_staff_member\' );
add_action( \'admin_init\', \'my_admin\' );
add_action( \'save_post\', \'add_staff_member_fields\', 10, 2);
//add_filter( \'template_include\', \'include_template_function\', 1 );