Esempio n. 1
0
 if ('page' == $post->post_type) {
     if (!current_user_can('edit_page', $post_ID)) {
         die(__('You are not allowed to edit this page.'));
     }
 } else {
     if (!current_user_can('edit_post', $post_ID)) {
         die(__('You are not allowed to edit this post.'));
     }
 }
 if ($do_autosave) {
     // Drafts and auto-drafts are just overwritten by autosave
     if ('auto-draft' == $post->post_status || 'draft' == $post->post_status) {
         $id = edit_post();
     } else {
         // Non drafts are not overwritten.  The autosave is stored in a special post revision.
         $revision_id = nxt_create_post_autosave($post->ID);
         if (is_nxt_error($revision_id)) {
             $id = $revision_id;
         } else {
             $id = $post->ID;
         }
     }
     $data = $message;
 } else {
     if (!empty($_POST['auto_draft'])) {
         $id = 0;
     } else {
         $id = $post->ID;
     }
 }
 if ($do_lock && empty($_POST['auto_draft']) && $id && is_numeric($id)) {
Esempio n. 2
0
/**
 * Save draft or manually autosave for showing preview.
 *
 * @package NXTClass
 * @since 2.7.0
 *
 * @uses get_post_status()
 * @uses edit_post()
 * @uses get_post()
 * @uses current_user_can()
 * @uses nxt_die()
 * @uses nxt_create_post_autosave()
 * @uses add_query_arg()
 * @uses nxt_create_nonce()
 *
 * @return str URL to redirect to show the preview
 */
function post_preview()
{
    $post_ID = (int) $_POST['post_ID'];
    $status = get_post_status($post_ID);
    if ('auto-draft' == $status) {
        nxt_die(__('Preview not available. Please save as a draft first.'));
    }
    if (isset($_POST['catslist'])) {
        $_POST['post_category'] = explode(",", $_POST['catslist']);
    }
    if (isset($_POST['tags_input'])) {
        $_POST['tags_input'] = explode(",", $_POST['tags_input']);
    }
    if ($_POST['post_type'] == 'page' || empty($_POST['post_category'])) {
        unset($_POST['post_category']);
    }
    $_POST['ID'] = $post_ID;
    $post = get_post($post_ID);
    if ('page' == $post->post_type) {
        if (!current_user_can('edit_page', $post_ID)) {
            nxt_die(__('You are not allowed to edit this page.'));
        }
    } else {
        if (!current_user_can('edit_post', $post_ID)) {
            nxt_die(__('You are not allowed to edit this post.'));
        }
    }
    if ('draft' == $post->post_status) {
        $id = edit_post();
    } else {
        // Non drafts are not overwritten.  The autosave is stored in a special post revision.
        $id = nxt_create_post_autosave($post->ID);
        if (!is_nxt_error($id)) {
            $id = $post->ID;
        }
    }
    if (is_nxt_error($id)) {
        nxt_die($id->get_error_message());
    }
    if ($_POST['post_status'] == 'draft') {
        $url = add_query_arg('preview', 'true', get_permalink($id));
    } else {
        $nonce = nxt_create_nonce('post_preview_' . $id);
        $url = add_query_arg(array('preview' => 'true', 'preview_id' => $id, 'preview_nonce' => $nonce), get_permalink($id));
    }
    return $url;
}