Php Wordpress插件-删除停用时创建的页面
我试着为自己制作一个自定义的帖子类型插件,并设法制作了一个函数,迄今为止为它创建了一个页面。我想做的是删除插件激活时所说的页面。代码应该是怎样的 这是我在插件激活时创建上述页面的代码:Php Wordpress插件-删除停用时创建的页面,php,wordpress,plugins,custom-post-type,Php,Wordpress,Plugins,Custom Post Type,我试着为自己制作一个自定义的帖子类型插件,并设法制作了一个函数,迄今为止为它创建了一个页面。我想做的是删除插件激活时所说的页面。代码应该是怎样的 这是我在插件激活时创建上述页面的代码: function create_video_pages() { $post = array( 'comment_status' => 'open', 'ping_status' => 'closed' , 'post_date' =
function create_video_pages() {
$post = array(
'comment_status' => 'open',
'ping_status' => 'closed' ,
'post_date' => date('Y-m-d H:i:s'),
'post_name' => 'videos',
'post_status' => 'publish' ,
'post_title' => 'Videos',
'post_type' => 'page',
);
$newvalue = wp_insert_post( $post, false );
update_option( 'vidpage', $newvalue );
}
您可以使用and函数来完成此操作,该函数将删除与post相关的所有内容
这个怎么样
function on_deactivating_your_plugin() {
$page = get_page_by_path( 'about' );
wp_delete_post($page->ID);
}
register_deactivation_hook( __FILE__, 'on_deactivating_your_plugin' );
从您的vidpage选项获取帖子id。 然后使用它删除该帖子
function deactivate_plugin() {
$page_id = get_option('vidpage');
wp_delete_post($page_id);
}
register_deactivation_hook( __FILE__, 'deactivate_plugin' );