2003-10-26 21:34:24 +01:00
|
|
|
<?php
|
2008-08-16 09:27:34 +02:00
|
|
|
/**
|
|
|
|
* Edit post administration panel.
|
|
|
|
*
|
|
|
|
* Manage Post actions: post, edit, delete, etc.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** WordPress Administration Bootstrap */
|
2010-04-18 08:14:45 +02:00
|
|
|
require_once('./admin.php');
|
2003-10-26 21:34:24 +01:00
|
|
|
|
2006-05-18 08:49:22 +02:00
|
|
|
$parent_file = 'edit.php';
|
|
|
|
$submenu_file = 'edit.php';
|
2003-12-18 10:36:13 +01:00
|
|
|
|
2006-07-03 21:03:37 +02:00
|
|
|
wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder'));
|
2006-04-19 10:02:16 +02:00
|
|
|
|
2010-01-12 17:50:37 +01:00
|
|
|
if ( isset($_GET['post']) )
|
|
|
|
$post_id = (int) $_GET['post'];
|
|
|
|
elseif ( isset($_POST['post_ID']) )
|
|
|
|
$post_id = (int) $_POST['post_ID'];
|
|
|
|
else
|
|
|
|
$post_id = 0;
|
|
|
|
$post_ID = $post_id;
|
|
|
|
$post = null;
|
|
|
|
$post_type_object = null;
|
2010-01-15 17:58:36 +01:00
|
|
|
$post_type = null;
|
2010-01-12 17:50:37 +01:00
|
|
|
if ( $post_id ) {
|
|
|
|
$post = get_post($post_id);
|
|
|
|
if ( $post ) {
|
|
|
|
$post_type_object = get_post_type_object($post->post_type);
|
2010-01-15 17:58:36 +01:00
|
|
|
if ( $post_type_object ) {
|
|
|
|
$post_type = $post->post_type;
|
|
|
|
$current_screen->post_type = $post->post_type;
|
|
|
|
$current_screen->id = $current_screen->post_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif ( isset($_POST['post_type']) ) {
|
|
|
|
$post_type_object = get_post_type_object($_POST['post_type']);
|
|
|
|
if ( $post_type_object ) {
|
|
|
|
$post_type = $post_type_object->name;
|
|
|
|
$current_screen->post_type = $post_type;
|
|
|
|
$current_screen->id = $current_screen->post_type;
|
2010-01-12 17:50:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-16 09:27:34 +02:00
|
|
|
/**
|
|
|
|
* Redirect to previous page.
|
|
|
|
*
|
2010-01-12 17:50:37 +01:00
|
|
|
* @param int $post_id Optional. Post ID.
|
2008-08-16 09:27:34 +02:00
|
|
|
*/
|
2010-01-12 17:50:37 +01:00
|
|
|
function redirect_post($post_id = '') {
|
2009-10-14 07:53:49 +02:00
|
|
|
if ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
|
2008-09-06 08:10:38 +02:00
|
|
|
if ( isset($_POST['saveasdraft']) )
|
|
|
|
$location = 'sidebar.php?a=c';
|
|
|
|
elseif ( isset($_POST['publish']) )
|
|
|
|
$location = 'sidebar.php?a=b';
|
2009-10-10 09:24:05 +02:00
|
|
|
} elseif ( isset($_POST['save']) || isset($_POST['publish']) ) {
|
2010-01-12 17:50:37 +01:00
|
|
|
$status = get_post_status( $post_id );
|
2009-10-10 09:24:05 +02:00
|
|
|
|
2009-05-02 23:44:09 +02:00
|
|
|
if ( isset( $_POST['publish'] ) ) {
|
2009-10-10 09:24:05 +02:00
|
|
|
switch ( $status ) {
|
2009-09-01 23:15:20 +02:00
|
|
|
case 'pending':
|
2009-10-10 09:24:05 +02:00
|
|
|
$message = 8;
|
2009-09-01 23:15:20 +02:00
|
|
|
break;
|
|
|
|
case 'future':
|
2009-10-10 09:24:05 +02:00
|
|
|
$message = 9;
|
2009-09-01 23:15:20 +02:00
|
|
|
break;
|
|
|
|
default:
|
2009-10-10 09:24:05 +02:00
|
|
|
$message = 6;
|
2009-09-01 23:15:20 +02:00
|
|
|
}
|
2009-05-02 23:44:09 +02:00
|
|
|
} else {
|
2009-10-10 09:24:05 +02:00
|
|
|
$message = 'draft' == $status ? 10 : 1;
|
2008-09-06 01:54:49 +02:00
|
|
|
}
|
2009-10-10 09:24:05 +02:00
|
|
|
|
2010-01-12 17:50:37 +01:00
|
|
|
$location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) );
|
2009-10-10 09:24:05 +02:00
|
|
|
} elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) {
|
2008-03-26 19:55:24 +01:00
|
|
|
$location = add_query_arg( 'message', 2, wp_get_referer() );
|
|
|
|
$location = explode('#', $location);
|
|
|
|
$location = $location[0] . '#postcustom';
|
2009-10-10 09:24:05 +02:00
|
|
|
} elseif ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) {
|
2008-03-26 19:55:24 +01:00
|
|
|
$location = add_query_arg( 'message', 3, wp_get_referer() );
|
|
|
|
$location = explode('#', $location);
|
|
|
|
$location = $location[0] . '#postcustom';
|
2008-08-20 23:42:31 +02:00
|
|
|
} elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
|
2010-01-12 17:50:37 +01:00
|
|
|
$location = "post.php?action=edit&post=$post_id&message=7";
|
2008-03-26 19:55:24 +01:00
|
|
|
} else {
|
2010-01-12 17:50:37 +01:00
|
|
|
$location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) );
|
2008-03-26 19:55:24 +01:00
|
|
|
}
|
|
|
|
|
2010-01-12 17:50:37 +01:00
|
|
|
wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) );
|
2008-03-26 19:55:24 +01:00
|
|
|
}
|
|
|
|
|
2006-04-19 10:02:16 +02:00
|
|
|
if ( isset( $_POST['deletepost'] ) )
|
|
|
|
$action = 'delete';
|
2008-10-31 23:47:07 +01:00
|
|
|
elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
|
|
|
|
$action = 'preview';
|
2005-04-16 18:31:38 +02:00
|
|
|
|
2009-12-02 00:28:20 +01:00
|
|
|
$sendback = wp_get_referer();
|
2010-01-24 21:50:50 +01:00
|
|
|
if ( strpos($sendback, 'post.php') !== false || strpos($sendback, 'post-new.php') !== false ) {
|
2009-12-02 00:28:20 +01:00
|
|
|
$sendback = admin_url('edit.php');
|
2010-01-24 21:50:50 +01:00
|
|
|
$sendback .= ( !empty( $post_type ) ) ? '?post_type=' . $post_type : '';
|
|
|
|
} else {
|
2009-12-02 00:28:20 +01:00
|
|
|
$sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback );
|
2010-01-24 21:50:50 +01:00
|
|
|
}
|
2009-12-02 00:28:20 +01:00
|
|
|
|
2003-10-26 21:34:24 +01:00
|
|
|
switch($action) {
|
2006-03-29 03:51:55 +02:00
|
|
|
case 'postajaxpost':
|
2004-04-28 06:49:16 +02:00
|
|
|
case 'post':
|
2008-08-20 23:42:31 +02:00
|
|
|
case 'post-quickpress-publish':
|
|
|
|
case 'post-quickpress-save':
|
2010-01-15 17:58:36 +01:00
|
|
|
check_admin_referer('add-' . $post_type);
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2008-08-20 23:42:31 +02:00
|
|
|
if ( 'post-quickpress-publish' == $action )
|
2008-09-06 07:16:56 +02:00
|
|
|
$_POST['publish'] = 'publish'; // tell write_post() to publish
|
|
|
|
|
|
|
|
if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) {
|
2008-09-03 09:13:51 +02:00
|
|
|
$_POST['comment_status'] = get_option('default_comment_status');
|
|
|
|
$_POST['ping_status'] = get_option('default_ping_status');
|
2008-09-06 07:16:56 +02:00
|
|
|
}
|
2008-08-20 23:42:31 +02:00
|
|
|
|
|
|
|
if ( !empty( $_POST['quickpress_post_ID'] ) ) {
|
|
|
|
$_POST['post_ID'] = (int) $_POST['quickpress_post_ID'];
|
2010-01-12 17:50:37 +01:00
|
|
|
$post_id = edit_post();
|
2008-08-20 23:42:31 +02:00
|
|
|
} else {
|
2010-01-12 17:50:37 +01:00
|
|
|
$post_id = 'postajaxpost' == $action ? edit_post() : write_post();
|
2008-08-20 23:42:31 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 01:32:34 +02:00
|
|
|
if ( 0 === strpos( $action, 'post-quickpress' ) ) {
|
2010-01-12 17:50:37 +01:00
|
|
|
$_POST['post_ID'] = $post_id;
|
2008-08-20 23:42:31 +02:00
|
|
|
// output the quickpress dashboard widget
|
|
|
|
require_once(ABSPATH . 'wp-admin/includes/dashboard.php');
|
2008-10-09 01:32:34 +02:00
|
|
|
wp_dashboard_quick_press();
|
2008-08-20 23:42:31 +02:00
|
|
|
exit;
|
|
|
|
}
|
2003-10-26 21:34:24 +01:00
|
|
|
|
2010-01-12 17:50:37 +01:00
|
|
|
redirect_post($post_id);
|
2004-04-28 06:49:16 +02:00
|
|
|
exit();
|
|
|
|
break;
|
2003-10-26 21:34:24 +01:00
|
|
|
|
2004-04-28 06:49:16 +02:00
|
|
|
case 'edit':
|
2006-02-21 07:11:46 +01:00
|
|
|
$editing = true;
|
2008-02-06 22:40:52 +01:00
|
|
|
|
2010-01-12 17:50:37 +01:00
|
|
|
if ( empty( $post_id ) ) {
|
2008-02-06 22:40:52 +01:00
|
|
|
wp_redirect("post.php");
|
|
|
|
exit();
|
|
|
|
}
|
2010-01-12 17:50:37 +01:00
|
|
|
|
|
|
|
$p = $post_id;
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2009-08-12 12:57:15 +02:00
|
|
|
if ( empty($post->ID) )
|
2010-01-12 17:50:37 +01:00
|
|
|
wp_die( __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?') );
|
2009-08-12 12:57:15 +02:00
|
|
|
|
2010-05-12 22:45:18 +02:00
|
|
|
if ( !current_user_can($post_type_object->cap->edit_post, $post_id) )
|
2010-01-12 17:50:37 +01:00
|
|
|
wp_die( __('You are not allowed to edit this item.') );
|
2009-08-12 12:57:15 +02:00
|
|
|
|
|
|
|
if ( 'trash' == $post->post_status )
|
2010-01-12 17:50:37 +01:00
|
|
|
wp_die( __('You can’t edit this item because it is in the Trash. Please restore it and try again.') );
|
2007-08-16 00:31:19 +02:00
|
|
|
|
2010-01-04 17:58:43 +01:00
|
|
|
if ( null == $post_type_object )
|
|
|
|
wp_die( __('Unknown post type.') );
|
|
|
|
|
|
|
|
$post_type = $post->post_type;
|
2010-01-12 17:50:37 +01:00
|
|
|
if ( 'post' == $post_type ) {
|
|
|
|
$parent_file = "edit.php";
|
|
|
|
$submenu_file = "edit.php";
|
|
|
|
} else {
|
2010-01-15 17:58:36 +01:00
|
|
|
$parent_file = "edit.php?post_type=$post_type";
|
|
|
|
$submenu_file = "edit.php?post_type=$post_type";
|
2010-01-04 17:58:43 +01:00
|
|
|
}
|
|
|
|
|
2009-08-12 12:57:15 +02:00
|
|
|
if ( $last = wp_check_post_lock( $post->ID ) ) {
|
2009-09-13 10:52:39 +02:00
|
|
|
add_action('admin_notices', '_admin_notice_post_locked' );
|
2009-08-12 12:57:15 +02:00
|
|
|
} else {
|
|
|
|
wp_set_post_lock( $post->ID );
|
|
|
|
wp_enqueue_script('autosave');
|
2008-02-29 10:51:36 +01:00
|
|
|
}
|
2008-01-03 02:34:11 +01:00
|
|
|
|
2010-05-11 21:52:50 +02:00
|
|
|
$title = $post_type_object->labels->edit_item;
|
2010-01-12 17:50:37 +01:00
|
|
|
$post = get_post_to_edit($post_id);
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2010-04-16 16:03:48 +02:00
|
|
|
if ( post_type_supports($post_type, 'comments') ) {
|
|
|
|
wp_enqueue_script('admin-comments');
|
|
|
|
enqueue_comment_hotkeys_js();
|
|
|
|
}
|
|
|
|
|
2010-04-18 08:14:45 +02:00
|
|
|
include('./edit-form-advanced.php');
|
2004-10-22 16:41:01 +02:00
|
|
|
|
2004-04-28 06:49:16 +02:00
|
|
|
break;
|
|
|
|
|
2005-12-13 20:19:56 +01:00
|
|
|
case 'editattachment':
|
2006-05-27 01:08:05 +02:00
|
|
|
check_admin_referer('update-attachment_' . $post_id);
|
2006-05-03 00:36:06 +02:00
|
|
|
|
2005-12-13 20:19:56 +01:00
|
|
|
// Don't let these be changed
|
|
|
|
unset($_POST['guid']);
|
2006-02-09 11:03:48 +01:00
|
|
|
$_POST['post_type'] = 'attachment';
|
2005-12-13 20:19:56 +01:00
|
|
|
|
|
|
|
// Update the thumbnail filename
|
2006-12-05 23:37:19 +01:00
|
|
|
$newmeta = wp_get_attachment_metadata( $post_id, true );
|
2005-12-13 20:19:56 +01:00
|
|
|
$newmeta['thumb'] = $_POST['thumb'];
|
|
|
|
|
2006-12-05 23:37:19 +01:00
|
|
|
wp_update_attachment_metadata( $post_id, $newmeta );
|
2005-12-13 20:19:56 +01:00
|
|
|
|
2004-04-28 06:49:16 +02:00
|
|
|
case 'editpost':
|
2010-01-15 17:58:36 +01:00
|
|
|
check_admin_referer('update-' . $post_type . '_' . $post_id);
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2010-01-12 17:50:37 +01:00
|
|
|
$post_id = edit_post();
|
2006-06-24 09:34:35 +02:00
|
|
|
|
2010-01-12 17:50:37 +01:00
|
|
|
redirect_post($post_id); // Send user on their way while we keep working
|
2005-02-14 10:46:08 +01:00
|
|
|
|
2004-04-30 10:56:49 +02:00
|
|
|
exit();
|
2003-11-12 16:22:47 +01:00
|
|
|
break;
|
2003-11-06 01:34:41 +01:00
|
|
|
|
2009-07-30 15:39:34 +02:00
|
|
|
case 'trash':
|
2010-01-15 17:58:36 +01:00
|
|
|
check_admin_referer('trash-' . $post_type . '_' . $post_id);
|
2009-07-30 15:39:34 +02:00
|
|
|
|
|
|
|
$post = & get_post($post_id);
|
|
|
|
|
2010-05-12 22:45:18 +02:00
|
|
|
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
|
2010-04-20 16:54:36 +02:00
|
|
|
wp_die( __('You are not allowed to move this item to the Trash.') );
|
2009-07-30 15:39:34 +02:00
|
|
|
|
|
|
|
if ( ! wp_trash_post($post_id) )
|
2010-04-20 16:54:36 +02:00
|
|
|
wp_die( __('Error in moving to Trash.') );
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2009-12-02 00:28:20 +01:00
|
|
|
wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
|
2009-07-30 15:39:34 +02:00
|
|
|
exit();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'untrash':
|
2010-01-15 17:58:36 +01:00
|
|
|
check_admin_referer('untrash-' . $post_type . '_' . $post_id);
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2010-05-12 22:45:18 +02:00
|
|
|
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
|
2010-04-20 16:54:36 +02:00
|
|
|
wp_die( __('You are not allowed to move this item out of the Trash.') );
|
2009-07-30 15:39:34 +02:00
|
|
|
|
|
|
|
if ( ! wp_untrash_post($post_id) )
|
2010-04-20 16:54:36 +02:00
|
|
|
wp_die( __('Error in restoring from Trash.') );
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2009-12-02 00:28:20 +01:00
|
|
|
wp_redirect( add_query_arg('untrashed', 1, $sendback) );
|
2009-07-30 15:39:34 +02:00
|
|
|
exit();
|
|
|
|
break;
|
|
|
|
|
2004-04-28 06:49:16 +02:00
|
|
|
case 'delete':
|
2010-01-15 17:58:36 +01:00
|
|
|
check_admin_referer('delete-' . $post_type . '_' . $post_id);
|
2005-12-13 20:19:56 +01:00
|
|
|
|
2010-05-12 22:45:18 +02:00
|
|
|
if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
|
2010-01-12 17:50:37 +01:00
|
|
|
wp_die( __('You are not allowed to delete this item.') );
|
2004-04-28 06:49:16 +02:00
|
|
|
|
2009-12-12 07:40:16 +01:00
|
|
|
$force = !EMPTY_TRASH_DAYS;
|
2006-02-09 11:03:48 +01:00
|
|
|
if ( $post->post_type == 'attachment' ) {
|
2009-12-12 07:40:16 +01:00
|
|
|
$force = ( $force || !MEDIA_TRASH );
|
|
|
|
if ( ! wp_delete_attachment($post_id, $force) )
|
2010-04-20 16:54:36 +02:00
|
|
|
wp_die( __('Error in deleting.') );
|
2005-12-15 23:26:22 +01:00
|
|
|
} else {
|
2009-12-12 07:40:16 +01:00
|
|
|
if ( !wp_delete_post($post_id, $force) )
|
2010-04-20 16:54:36 +02:00
|
|
|
wp_die( __('Error in deleting.') );
|
2005-12-15 23:26:22 +01:00
|
|
|
}
|
2003-11-12 16:22:47 +01:00
|
|
|
|
2009-12-02 00:28:20 +01:00
|
|
|
wp_redirect( add_query_arg('deleted', 1, $sendback) );
|
2006-02-21 07:11:46 +01:00
|
|
|
exit();
|
2003-11-12 16:22:47 +01:00
|
|
|
break;
|
2004-04-28 06:49:16 +02:00
|
|
|
|
2008-10-31 23:47:07 +01:00
|
|
|
case 'preview':
|
|
|
|
check_admin_referer( 'autosave', 'autosavenonce' );
|
|
|
|
|
2008-11-04 14:00:12 +01:00
|
|
|
$url = post_preview();
|
2008-10-31 23:47:07 +01:00
|
|
|
|
|
|
|
wp_redirect($url);
|
|
|
|
exit();
|
|
|
|
break;
|
|
|
|
|
2004-04-28 06:49:16 +02:00
|
|
|
default:
|
2010-01-12 17:50:37 +01:00
|
|
|
wp_redirect('edit.php');
|
2006-04-04 02:12:43 +02:00
|
|
|
exit();
|
2004-04-28 06:49:16 +02:00
|
|
|
break;
|
2003-10-26 21:34:24 +01:00
|
|
|
} // end switch
|
2010-04-18 08:14:45 +02:00
|
|
|
include('./admin-footer.php');
|
2003-11-12 16:22:47 +01:00
|
|
|
?>
|