2015-09-28 35 views
1

我試圖製作一個自定義的帖子類型插件供我自己使用,並設法創建一個函數,爲其創建頁面。我想要做的是在插件激活時刪除所述頁面。代碼應該如何?WordPress插件 - 刪除頁面停用時創建

這是我在插件激活創建表示網頁代碼:

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); 
} 

回答

3

從您的vidpage選項中獲取post_id。 然後用它來刪除該帖子。

function deactivate_plugin() { 

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

} 
register_deactivation_hook(__FILE__, 'deactivate_plugin'); 
1

你可以做到這一點使用register_deactivation_hook和功能wp_delete_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'); 
相關問題