试着做这样的事情。
<?php
/*
Plugin Name: My Custom Plugin
Plugin URI:
Description:
Author:
Version: 1.0
Author URI:
*/
/* Runs when plugin is activated */
register_activation_hook(__FILE__, \'mcp_install\');
/* Runs on plugin deactivation*/
register_deactivation_hook( __FILE__, \'mcp_remove\' );
function mcp_install() {
//Make sure that .htaccess file is there.
add_action(\'init\', \'change_permalinks\', 20);
//Activate your theme also.
}
function mcp_remove() {
}
function mcp_change_permalinks() {
global $wp_rewrite;
$wp_rewrite->set_permalink_structure(\'/%postname%/\');
$wp_rewrite->flush_rules();
}
function mcp_custom_init() {
$labels = array(
\'name\' => \'Books\',
\'singular_name\' => \'Book\',
\'add_new\' => \'Add New\',
\'add_new_item\' => \'Add New Book\',
\'edit_item\' => \'Edit Book\',
\'new_item\' => \'New Book\',
\'all_items\' => \'All Books\',
\'view_item\' => \'View Book\',
\'search_items\' => \'Search Books\',
\'not_found\' => \'No books found\',
\'not_found_in_trash\' => \'No books found in Trash\',
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Books\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'book\' ),
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
);
register_post_type( \'book\', $args );
}
add_action( \'init\', \'mcp_custom_init\', 10);