I’m using something like this to add a page when my WordPress plugin is activated.
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');
This is fine (and dandy) but I don’t want to re-create this page every time this plugin is deactivated. How do I check to see if this page exists OR unpublish on plugin deactivation?
You can check if the page exists using WP_Query. Simple as that.
To delete on deactivation, use register_deactivation_hook.