防止插件激活时重复页面(或取消发布插件停用时的页面)

时间:2011-11-17 03:00:39

标签: wordpress-plugin wordpress

当我的Wordpress插件被激活时,我正在使用这样的东西来添加页面。

function create_wordpress_pages(){

$my_post = array();
$my_post['post_title'] = 'My post';
$my_post['post_content'] = 'This is my post.';
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
$my_post['post_type'] = 'page';

wp_insert_post( $my_post );
}
register_activation_hook(__FILE__, 'create_wordpress_pages');

这很好(和花花公子),但我不希望每次停用此插件时重新创建此页面。如何检查此页面是否存在或取消发布插件停用?

1 个答案:

答案 0 :(得分:0)

您可以使用WP_Query检查页面是否存在。就那么简单。 要在停用时删除,请使用register_deactivation_hook

相关问题