02刪除post

function wporg_frontend_delete_link() {
     $url = add_query_arg(
         array(
             'action'=>'wporg_frontend_delete',
             'post'=>get_the_ID();
         ),
         home_url(),
     );
     echo "<a href="{$url}">Delete</a>";
}

if ( isset($_REQUEST['action']) && $_REQUEST['action']=='wporg_frontend_delete' ) {
     add_action('init','wporg_frontend_delete_post');
}

function wporg_frontend_delete_post() {

    // Get the ID of the post.
    $post_id = ( isset( $_REQUEST['post'] ) ?  get_post( (int) $_REQUEST['post'] ) : false;

    // No post? Oh well..
    if ( empty($post_id) )
        return;

    // Delete post
    wp_trash_post( $post_id );
    // Redirect to admin page
    $redirect = admin_url('edit.php');
    wp_safe_redirect( $redirect );
    exit;
}
wordpress
CH02用戶資料CH03基本APICH05 分類頁面Category.phpCH09Screen Options(顯示選項)CH10外掛pluginsCH11 add_actionCH12 add_filterCH13Meta Box(自訂區塊)CH14widget(自訂模組)CH15 DBCH16AJAXCH17ShortcodeCH20 wordpress muCH30WooCommerce