2003-10-26 15:34:24 -05:00
|
|
|
<?php
|
2008-08-16 03:27:34 -04:00
|
|
|
/**
|
|
|
|
* Edit post administration panel.
|
|
|
|
*
|
|
|
|
* Manage Post actions: post, edit, delete, etc.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** WordPress Administration Bootstrap */
|
2004-10-18 23:03:06 -04:00
|
|
|
require_once('admin.php');
|
2003-10-26 15:34:24 -05:00
|
|
|
|
2006-05-18 02:49:22 -04:00
|
|
|
$parent_file = 'edit.php';
|
|
|
|
$submenu_file = 'edit.php';
|
2003-12-18 04:36:13 -05:00
|
|
|
|
2006-07-03 15:03:37 -04: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 04:02:16 -04:00
|
|
|
|
2008-08-16 03:27:34 -04:00
|
|
|
/**
|
|
|
|
* Redirect to previous page.
|
|
|
|
*
|
|
|
|
* @param int $post_ID Optional. Post ID.
|
|
|
|
*/
|
2008-03-26 14:55:24 -04:00
|
|
|
function redirect_post($post_ID = '') {
|
|
|
|
global $action;
|
|
|
|
|
|
|
|
$referredby = '';
|
2008-04-21 13:54:56 -04:00
|
|
|
if ( !empty($_POST['referredby']) ) {
|
2008-03-26 14:55:24 -04:00
|
|
|
$referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
|
2008-04-21 13:54:56 -04:00
|
|
|
$referredby = remove_query_arg('_wp_original_http_referer', $referredby);
|
|
|
|
}
|
2008-03-26 14:55:24 -04:00
|
|
|
$referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
|
|
|
|
|
2008-03-26 19:41:41 -04:00
|
|
|
if ( !empty($_POST['mode']) && 'bookmarklet' == $_POST['mode'] ) {
|
2008-03-26 14:55:24 -04:00
|
|
|
$location = $_POST['referredby'];
|
2008-03-26 19:41:41 -04:00
|
|
|
} elseif ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
|
2008-09-06 02:10:38 -04:00
|
|
|
if ( isset($_POST['saveasdraft']) )
|
|
|
|
$location = 'sidebar.php?a=c';
|
|
|
|
elseif ( isset($_POST['publish']) )
|
|
|
|
$location = 'sidebar.php?a=b';
|
2009-05-02 17:44:09 -04:00
|
|
|
} elseif ( ( isset($_POST['save']) || isset($_POST['publish']) ) ) {
|
|
|
|
if ( isset( $_POST['publish'] ) ) {
|
|
|
|
if ( 'pending' == get_post_status( $post_ID ) )
|
|
|
|
$location = add_query_arg( 'message', 8, get_edit_post_link( $post_ID, 'url' ) );
|
|
|
|
else
|
|
|
|
$location = add_query_arg( 'message', 6, get_edit_post_link( $post_ID, 'url' ) );
|
|
|
|
} else {
|
|
|
|
$location = add_query_arg( 'message', 1, get_edit_post_link( $post_ID, 'url' ) );
|
2008-09-05 19:54:49 -04:00
|
|
|
}
|
2008-03-26 14:55:24 -04:00
|
|
|
} elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
|
|
|
|
$location = add_query_arg( 'message', 2, wp_get_referer() );
|
|
|
|
$location = explode('#', $location);
|
|
|
|
$location = $location[0] . '#postcustom';
|
|
|
|
} elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
|
|
|
|
$location = add_query_arg( 'message', 3, wp_get_referer() );
|
|
|
|
$location = explode('#', $location);
|
|
|
|
$location = $location[0] . '#postcustom';
|
|
|
|
} elseif ($action == 'editattachment') {
|
|
|
|
$location = 'attachments.php';
|
2008-08-20 17:42:31 -04:00
|
|
|
} elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
|
|
|
|
$location = "post.php?action=edit&post=$post_ID&message=7";
|
2008-03-26 14:55:24 -04:00
|
|
|
} else {
|
2008-07-29 01:22:58 -04:00
|
|
|
$location = add_query_arg( 'message', 4, get_edit_post_link( $post_ID, 'url' ) );
|
2008-03-26 14:55:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
wp_redirect( $location );
|
|
|
|
}
|
|
|
|
|
2006-04-19 04:02:16 -04:00
|
|
|
if ( isset( $_POST['deletepost'] ) )
|
|
|
|
$action = 'delete';
|
2008-10-31 18:47:07 -04:00
|
|
|
elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
|
|
|
|
$action = 'preview';
|
2005-04-16 12:31:38 -04:00
|
|
|
|
2003-10-26 15:34:24 -05:00
|
|
|
switch($action) {
|
2006-03-28 20:51:55 -05:00
|
|
|
case 'postajaxpost':
|
2004-04-28 00:49:16 -04:00
|
|
|
case 'post':
|
2008-08-20 17:42:31 -04:00
|
|
|
case 'post-quickpress-publish':
|
|
|
|
case 'post-quickpress-save':
|
2006-05-02 18:36:06 -04:00
|
|
|
check_admin_referer('add-post');
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-08-20 17:42:31 -04:00
|
|
|
if ( 'post-quickpress-publish' == $action )
|
2008-09-06 01:16:56 -04:00
|
|
|
$_POST['publish'] = 'publish'; // tell write_post() to publish
|
|
|
|
|
|
|
|
if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) {
|
2008-09-03 03:13:51 -04:00
|
|
|
$_POST['comment_status'] = get_option('default_comment_status');
|
|
|
|
$_POST['ping_status'] = get_option('default_ping_status');
|
2008-09-06 01:16:56 -04:00
|
|
|
}
|
2008-08-20 17:42:31 -04:00
|
|
|
|
|
|
|
if ( !empty( $_POST['quickpress_post_ID'] ) ) {
|
|
|
|
$_POST['post_ID'] = (int) $_POST['quickpress_post_ID'];
|
|
|
|
$post_ID = edit_post();
|
|
|
|
} else {
|
|
|
|
$post_ID = 'postajaxpost' == $action ? edit_post() : write_post();
|
|
|
|
}
|
|
|
|
|
2008-10-08 19:32:34 -04:00
|
|
|
if ( 0 === strpos( $action, 'post-quickpress' ) ) {
|
2008-08-20 17:42:31 -04:00
|
|
|
$_POST['post_ID'] = $post_ID;
|
|
|
|
// output the quickpress dashboard widget
|
|
|
|
require_once(ABSPATH . 'wp-admin/includes/dashboard.php');
|
2008-10-08 19:32:34 -04:00
|
|
|
wp_dashboard_quick_press();
|
2008-08-20 17:42:31 -04:00
|
|
|
exit;
|
|
|
|
}
|
2003-10-26 15:34:24 -05:00
|
|
|
|
2008-03-26 14:55:24 -04:00
|
|
|
redirect_post($post_ID);
|
2004-04-28 00:49:16 -04:00
|
|
|
exit();
|
|
|
|
break;
|
2003-10-26 15:34:24 -05:00
|
|
|
|
2004-04-28 00:49:16 -04:00
|
|
|
case 'edit':
|
2006-02-21 01:11:46 -05:00
|
|
|
$editing = true;
|
2008-02-06 16:40:52 -05:00
|
|
|
|
|
|
|
if ( empty( $_GET['post'] ) ) {
|
|
|
|
wp_redirect("post.php");
|
|
|
|
exit();
|
|
|
|
}
|
2005-06-18 22:51:48 -04:00
|
|
|
$post_ID = $p = (int) $_GET['post'];
|
2006-02-21 01:11:46 -05:00
|
|
|
$post = get_post($post_ID);
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2009-05-05 00:28:05 -04:00
|
|
|
if ( empty($post->ID) ) wp_die( __('You attempted to edit a post that doesn’t exist. Perhaps it was deleted?') );
|
2007-08-15 18:31:19 -04:00
|
|
|
|
2008-04-18 19:38:21 -04:00
|
|
|
if ( 'post' != $post->post_type ) {
|
|
|
|
wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
|
2007-01-22 03:16:58 -05:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2008-01-02 20:34:11 -05:00
|
|
|
wp_enqueue_script('post');
|
2008-02-18 12:11:12 -05:00
|
|
|
if ( user_can_richedit() )
|
|
|
|
wp_enqueue_script('editor');
|
2008-06-02 17:46:25 -04:00
|
|
|
add_thickbox();
|
2008-01-09 03:14:29 -05:00
|
|
|
wp_enqueue_script('media-upload');
|
2008-04-29 15:17:23 -04:00
|
|
|
wp_enqueue_script('word-count');
|
2008-08-24 02:56:22 -04:00
|
|
|
wp_enqueue_script( 'admin-comments' );
|
2008-10-16 18:23:32 -04:00
|
|
|
enqueue_comment_hotkeys_js();
|
2008-04-22 19:54:13 -04:00
|
|
|
|
|
|
|
if ( current_user_can('edit_post', $post_ID) ) {
|
|
|
|
if ( $last = wp_check_post_lock( $post->ID ) ) {
|
|
|
|
$last_user = get_userdata( $last );
|
|
|
|
$last_user_name = $last_user ? $last_user->display_name : __('Somebody');
|
2009-05-18 11:11:07 -04:00
|
|
|
$message = sprintf( __( 'Warning: %s is currently editing this post' ), esc_html( $last_user_name ) );
|
2008-04-22 19:54:13 -04:00
|
|
|
$message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
|
|
|
|
add_action('admin_notices', create_function( '', "echo '$message';" ) );
|
|
|
|
} else {
|
|
|
|
wp_set_post_lock( $post->ID );
|
|
|
|
wp_enqueue_script('autosave');
|
|
|
|
}
|
2008-02-29 04:51:36 -05:00
|
|
|
}
|
2008-01-02 20:34:11 -05:00
|
|
|
|
2008-10-31 12:40:55 -04:00
|
|
|
$title = __('Edit Post');
|
2008-10-16 20:36:18 -04:00
|
|
|
|
2005-07-11 18:39:50 -04:00
|
|
|
if ( !current_user_can('edit_post', $post_ID) )
|
2005-02-24 19:20:48 -05:00
|
|
|
die ( __('You are not allowed to edit this post.') );
|
2005-06-18 22:51:48 -04:00
|
|
|
|
|
|
|
$post = get_post_to_edit($post_ID);
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2006-02-21 01:11:46 -05:00
|
|
|
include('edit-form-advanced.php');
|
2004-10-22 10:41:01 -04:00
|
|
|
|
2004-04-28 00:49:16 -04:00
|
|
|
break;
|
|
|
|
|
2005-12-13 14:19:56 -05:00
|
|
|
case 'editattachment':
|
|
|
|
$post_id = (int) $_POST['post_ID'];
|
|
|
|
|
2006-05-26 19:08:05 -04:00
|
|
|
check_admin_referer('update-attachment_' . $post_id);
|
2006-05-02 18:36:06 -04:00
|
|
|
|
2005-12-13 14:19:56 -05:00
|
|
|
// Don't let these be changed
|
|
|
|
unset($_POST['guid']);
|
2006-02-09 05:03:48 -05:00
|
|
|
$_POST['post_type'] = 'attachment';
|
2005-12-13 14:19:56 -05:00
|
|
|
|
|
|
|
// Update the thumbnail filename
|
2006-12-05 17:37:19 -05:00
|
|
|
$newmeta = wp_get_attachment_metadata( $post_id, true );
|
2005-12-13 14:19:56 -05:00
|
|
|
$newmeta['thumb'] = $_POST['thumb'];
|
|
|
|
|
2006-12-05 17:37:19 -05:00
|
|
|
wp_update_attachment_metadata( $post_id, $newmeta );
|
2005-12-13 14:19:56 -05:00
|
|
|
|
2004-04-28 00:49:16 -04:00
|
|
|
case 'editpost':
|
2006-05-02 18:36:06 -04:00
|
|
|
$post_ID = (int) $_POST['post_ID'];
|
2006-05-26 19:08:05 -04:00
|
|
|
check_admin_referer('update-post_' . $post_ID);
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2005-09-08 16:38:30 -04:00
|
|
|
$post_ID = edit_post();
|
2006-06-24 03:34:35 -04:00
|
|
|
|
2008-03-26 14:55:24 -04:00
|
|
|
redirect_post($post_ID); // Send user on their way while we keep working
|
2005-02-14 04:46:08 -05:00
|
|
|
|
2004-04-30 04:56:49 -04:00
|
|
|
exit();
|
2003-11-12 10:22:47 -05:00
|
|
|
break;
|
2003-11-05 19:34:41 -05:00
|
|
|
|
2004-04-28 00:49:16 -04:00
|
|
|
case 'delete':
|
2004-11-26 23:46:54 -05:00
|
|
|
$post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
|
2006-05-26 19:08:05 -04:00
|
|
|
check_admin_referer('delete-post_' . $post_id);
|
2005-12-13 14:19:56 -05:00
|
|
|
|
|
|
|
$post = & get_post($post_id);
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2006-02-21 01:11:46 -05:00
|
|
|
if ( !current_user_can('delete_post', $post_id) )
|
2006-07-05 18:00:03 -04:00
|
|
|
wp_die( __('You are not allowed to delete this post.') );
|
2004-04-28 00:49:16 -04:00
|
|
|
|
2006-02-09 05:03:48 -05:00
|
|
|
if ( $post->post_type == 'attachment' ) {
|
2005-12-15 17:26:22 -05:00
|
|
|
if ( ! wp_delete_attachment($post_id) )
|
2006-07-05 18:00:03 -04:00
|
|
|
wp_die( __('Error in deleting...') );
|
2005-12-15 17:26:22 -05:00
|
|
|
} else {
|
2007-09-03 19:32:58 -04:00
|
|
|
if ( !wp_delete_post($post_id) )
|
2006-07-05 18:00:03 -04:00
|
|
|
wp_die( __('Error in deleting...') );
|
2005-12-15 17:26:22 -05:00
|
|
|
}
|
2003-11-12 10:22:47 -05:00
|
|
|
|
2006-06-24 03:34:35 -04:00
|
|
|
$sendback = wp_get_referer();
|
2008-12-01 13:02:16 -05:00
|
|
|
if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?deleted=1');
|
2008-05-27 13:46:01 -04:00
|
|
|
elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
|
2008-12-01 13:02:16 -05:00
|
|
|
else $sendback = add_query_arg('deleted', 1, $sendback);
|
2006-06-27 01:38:56 -04:00
|
|
|
wp_redirect($sendback);
|
2006-02-21 01:11:46 -05:00
|
|
|
exit();
|
2003-11-12 10:22:47 -05:00
|
|
|
break;
|
2004-04-28 00:49:16 -04:00
|
|
|
|
2008-10-31 18:47:07 -04:00
|
|
|
case 'preview':
|
|
|
|
check_admin_referer( 'autosave', 'autosavenonce' );
|
|
|
|
|
2008-11-04 08:00:12 -05:00
|
|
|
$url = post_preview();
|
2008-10-31 18:47:07 -04:00
|
|
|
|
|
|
|
wp_redirect($url);
|
|
|
|
exit();
|
|
|
|
break;
|
|
|
|
|
2004-04-28 00:49:16 -04:00
|
|
|
default:
|
2006-06-27 01:38:56 -04:00
|
|
|
wp_redirect('edit.php');
|
2006-04-03 20:12:43 -04:00
|
|
|
exit();
|
2004-04-28 00:49:16 -04:00
|
|
|
break;
|
2003-10-26 15:34:24 -05:00
|
|
|
} // end switch
|
2003-12-10 19:22:36 -05:00
|
|
|
include('admin-footer.php');
|
2003-11-12 10:22:47 -05:00
|
|
|
?>
|