我正在开发我的第一个插件,并尝试使用register_activation_hook()
和register_deactivation_hook()
... 我知道我做得不对:
/*====================================================*/
// 1.0 Actions to perform upon plugin activation
/*====================================================*/
register_activation_hook( __FILE__, \'construct_uploader_page\' );
register_activation_hook( __FILE__, \'construct_terms_page\' );
register_activation_hook( __FILE__, \'create_custom_user_role\' );
// Construct Event Photo Uploader template page
function construct_uploader_page() {
$post_id = -1;
// Setup custom vars
$author_id = 1;
$slug = \'event-photo-uploader\';
$title = \'Event Photo Uploader\';
// Check if page exists... if not, create it
if ( null == get_page_by_title( $title )) {
$uploader_page = array(
\'comment_status\' => \'closed\',
\'ping_status\' => \'closed\',
\'post_author\' => $author_id,
\'post_name\' => $slug,
\'post_title\' => $title,
\'post_status\' => \'publish\',
\'post_type\' => \'page\'
);
$post_id = wp_insert_post( $uploader_page );
if ( !$post_id ) {
wp_die( \'Error creating template page\' );
} else {
update_post_meta( $post_id, \'_wp_page_template\', \'custom-uploadr.php\' );
}
}
} // end construct uploader page
// Add Event Photo Uploader page
add_action( \'template_include\', \'uploadr_redirect\' );
// Callback to add menu items
function uploadr_redirect( $template ) {
$plugindir = dirname( __FILE__ );
// A Specific Custom Post Type
if ( is_page_template( \'custom-uploadr.php\' )) {
$template = $plugindir . \'/templates/custom-uploadr.php\';
}
return $template;
}
// Construct Terms and Usage template page
function construct_terms_page() {
$post_id = -1;
// Setup variables
$author_id = 1;
$slug = \'terms-and-usage\';
$title = \'Terms and Usage\';
// Check if page exists... if not, create it
if ( null == get_page_by_title( $title )) {
$uploader_page = array(
\'comment_status\' => \'closed\',
\'ping_status\' => \'closed\',
\'post_author\' => $author_id,
\'post_name\' => $slug,
\'post_title\' => $title,
\'post_status\' => \'publish\',
\'post_type\' => \'page\'
);
$post_id = wp_insert_post( $uploader_page );
if ( !$post_id ) {
wp_die( \'Error creating template page\' );
} else {
update_post_meta( $post_id, \'_wp_page_template\', \'terms-and-use.php\' );
}
}
} // end construct terms page
// Add Terms and Usage page
add_action( \'template_include\', \'terms_redirect\' );
// Callback to add menu items
function terms_redirect( $template ) {
$plugindir = dirname( __FILE__ );
// A Specific Custom Post Type
if ( is_page( \'Terms and Usage\' )) {
$template = $plugindir . \'/templates/terms-and-use.php\';
}
return $template;
}
// Create custom user-role for registration
function create_custom_user_role() {
$custom_role = get_role(\'subscriber\');
$standard_user = add_role( \'register\', \'Register User\', $custom_role->capabilities );
}
// End Activation function
我需要在插件激活时添加这三件事(两个页面和一个自定义角色),然后在插件停用时停用它们。。。我需要帮助;从我所看到的一切来看,应该只有一个
activation_hook()
还有一个
deactivation_hook()
, 但我需要激活/停用多个功能。
谢谢你的帮助!