Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress Plugin - Delete a Page Created when deactivating

I tried to make a custom post type plugin for my own use, and managed to make a function that creates the page for it so far. What I want to do is to delete the said page when the plugin is activated. How should the code be?

This is my code for creating the said page upon plugin activation:

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 );
}
like image 425
58YtQ2H83m17838963l61BU07Y8622 Avatar asked Feb 06 '26 05:02

58YtQ2H83m17838963l61BU07Y8622


1 Answers

Get the post_id from your vidpage option. Then use it to delete that post.

function deactivate_plugin() {

    $page_id = get_option('vidpage');
    wp_delete_post($page_id);

}
register_deactivation_hook( __FILE__, 'deactivate_plugin' );
like image 139
TeeDeJee Avatar answered Feb 09 '26 02:02

TeeDeJee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!