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 */
|
2013-09-25 02:18:11 +02:00
|
|
|
require_once( dirname( __FILE__ ) . '/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
|
|
|
|
2013-02-16 19:28:41 +01:00
|
|
|
wp_reset_vars( array( 'action' ) );
|
2006-04-19 10:02:16 +02:00
|
|
|
|
2011-10-24 20:34:08 +02:00
|
|
|
if ( isset( $_GET['post'] ) )
|
|
|
|
$post_id = $post_ID = (int) $_GET['post'];
|
|
|
|
elseif ( isset( $_POST['post_ID'] ) )
|
|
|
|
$post_id = $post_ID = (int) $_POST['post_ID'];
|
2011-10-31 18:08:36 +01:00
|
|
|
else
|
2011-10-24 20:34:08 +02:00
|
|
|
$post_id = $post_ID = 0;
|
|
|
|
|
2015-05-28 23:41:30 +02:00
|
|
|
/**
|
|
|
|
* @global string $post_type
|
|
|
|
* @global object $post_type_object
|
|
|
|
* @global WP_Post $post
|
|
|
|
*/
|
2015-01-10 06:29:22 +01:00
|
|
|
global $post_type, $post_type_object, $post;
|
2011-10-24 20:34:08 +02:00
|
|
|
|
|
|
|
if ( $post_id )
|
|
|
|
$post = get_post( $post_id );
|
|
|
|
|
|
|
|
if ( $post ) {
|
|
|
|
$post_type = $post->post_type;
|
|
|
|
$post_type_object = get_post_type_object( $post_type );
|
2010-01-12 17:50:37 +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();
|
2011-11-14 17:59:45 +01:00
|
|
|
if ( ! $sendback ||
|
|
|
|
strpos( $sendback, 'post.php' ) !== false ||
|
|
|
|
strpos( $sendback, 'post-new.php' ) !== false ) {
|
2012-09-22 00:52:54 +02:00
|
|
|
if ( 'attachment' == $post_type ) {
|
|
|
|
$sendback = admin_url( 'upload.php' );
|
|
|
|
} else {
|
|
|
|
$sendback = admin_url( 'edit.php' );
|
2015-03-05 23:31:24 +01:00
|
|
|
if ( ! empty( $post_type ) ) {
|
|
|
|
$sendback = add_query_arg( 'post_type', $post_type, $sendback );
|
|
|
|
}
|
2012-09-22 00:52:54 +02:00
|
|
|
}
|
2010-01-24 21:50:50 +01:00
|
|
|
} 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) {
|
2013-11-13 23:09:10 +01:00
|
|
|
case 'post-quickdraft-save':
|
|
|
|
// Check nonce and capabilities
|
|
|
|
$nonce = $_REQUEST['_wpnonce'];
|
|
|
|
$error_msg = false;
|
2014-03-20 02:31:15 +01:00
|
|
|
|
|
|
|
// For output of the quickdraft dashboard widget
|
|
|
|
require_once ABSPATH . 'wp-admin/includes/dashboard.php';
|
|
|
|
|
2013-11-13 23:09:10 +01:00
|
|
|
if ( ! wp_verify_nonce( $nonce, 'add-post' ) )
|
2013-11-17 04:21:10 +01:00
|
|
|
$error_msg = __( 'Unable to submit this form, please refresh and try again.' );
|
2013-11-13 23:09:10 +01:00
|
|
|
|
2015-10-20 07:49:24 +02:00
|
|
|
if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
|
2015-07-22 06:02:25 +02:00
|
|
|
exit;
|
|
|
|
}
|
2013-11-13 23:09:10 +01:00
|
|
|
|
|
|
|
if ( $error_msg )
|
2013-11-15 23:23:09 +01:00
|
|
|
return wp_dashboard_quick_press( $error_msg );
|
2013-11-13 23:09:10 +01:00
|
|
|
|
|
|
|
$post = get_post( $_REQUEST['post_ID'] );
|
|
|
|
check_admin_referer( 'add-' . $post->post_type );
|
2014-01-16 21:24:13 +01:00
|
|
|
|
2015-07-03 00:32:25 +02:00
|
|
|
$_POST['comment_status'] = get_default_comment_status( $post->post_type );
|
|
|
|
$_POST['ping_status'] = get_default_comment_status( $post->post_type, 'pingback' );
|
2014-01-16 21:24:13 +01:00
|
|
|
|
2013-11-13 23:09:10 +01:00
|
|
|
edit_post();
|
2013-11-15 23:23:09 +01:00
|
|
|
wp_dashboard_quick_press();
|
2013-11-13 23:09:10 +01:00
|
|
|
exit;
|
|
|
|
|
2006-03-29 03:51:55 +02:00
|
|
|
case 'postajaxpost':
|
2004-04-28 06:49:16 +02:00
|
|
|
case 'post':
|
2013-11-15 23:29:09 +01:00
|
|
|
check_admin_referer( 'add-' . $post_type );
|
2013-11-13 23:09:10 +01:00
|
|
|
$post_id = 'postajaxpost' == $action ? edit_post() : write_post();
|
2013-11-15 23:29:09 +01:00
|
|
|
redirect_post( $post_id );
|
2004-04-28 06:49:16 +02:00
|
|
|
exit();
|
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 ) ) {
|
2010-10-27 12:43:43 +02:00
|
|
|
wp_redirect( admin_url('post.php') );
|
2008-02-06 22:40:52 +01:00
|
|
|
exit();
|
|
|
|
}
|
2010-01-12 17:50:37 +01:00
|
|
|
|
2013-05-08 20:56:54 +02:00
|
|
|
if ( ! $post )
|
|
|
|
wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) );
|
2009-08-12 12:57:15 +02:00
|
|
|
|
2013-05-08 20:56:54 +02:00
|
|
|
if ( ! $post_type_object )
|
2017-01-10 03:40:42 +01:00
|
|
|
wp_die( __( 'Invalid post type.' ) );
|
2012-04-27 21:32:32 +02:00
|
|
|
|
2015-09-15 12:27:29 +02:00
|
|
|
if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ) ) ) {
|
2016-06-29 17:16:29 +02:00
|
|
|
wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ) );
|
2015-09-15 12:27:29 +02:00
|
|
|
}
|
|
|
|
|
2013-07-08 22:05:42 +02:00
|
|
|
if ( ! current_user_can( 'edit_post', $post_id ) )
|
2016-06-29 17:16:29 +02:00
|
|
|
wp_die( __( 'Sorry, you are not allowed to edit this item.' ) );
|
2009-08-12 12:57:15 +02:00
|
|
|
|
|
|
|
if ( 'trash' == $post->post_status )
|
2013-05-08 20:56:54 +02: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
|
|
|
|
2013-05-08 20:56:54 +02:00
|
|
|
if ( ! empty( $_GET['get-post-lock'] ) ) {
|
2015-08-04 06:54:34 +02:00
|
|
|
check_admin_referer( 'lock-post_' . $post_id );
|
2013-03-12 04:22:30 +01:00
|
|
|
wp_set_post_lock( $post_id );
|
|
|
|
wp_redirect( get_edit_post_link( $post_id, 'url' ) );
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2010-01-04 17:58:43 +01:00
|
|
|
$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";
|
2011-05-19 03:34:34 +02:00
|
|
|
$post_new_file = "post-new.php";
|
2012-09-22 00:52:54 +02:00
|
|
|
} elseif ( 'attachment' == $post_type ) {
|
|
|
|
$parent_file = 'upload.php';
|
|
|
|
$submenu_file = 'upload.php';
|
|
|
|
$post_new_file = 'media-new.php';
|
2010-01-12 17:50:37 +01:00
|
|
|
} else {
|
2011-01-06 05:11:14 +01:00
|
|
|
if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true )
|
2010-12-29 17:25:22 +01:00
|
|
|
$parent_file = $post_type_object->show_in_menu;
|
|
|
|
else
|
|
|
|
$parent_file = "edit.php?post_type=$post_type";
|
2010-01-15 17:58:36 +01:00
|
|
|
$submenu_file = "edit.php?post_type=$post_type";
|
2011-05-19 03:34:34 +02:00
|
|
|
$post_new_file = "post-new.php?post_type=$post_type";
|
2010-01-04 17:58:43 +01:00
|
|
|
}
|
|
|
|
|
2013-03-12 04:22:30 +01:00
|
|
|
if ( ! wp_check_post_lock( $post->ID ) ) {
|
2011-09-27 22:52:07 +02:00
|
|
|
$active_post_lock = wp_set_post_lock( $post->ID );
|
2012-11-20 20:46:38 +01:00
|
|
|
|
|
|
|
if ( 'attachment' !== $post_type )
|
|
|
|
wp_enqueue_script('autosave');
|
2008-02-29 10:51:36 +01:00
|
|
|
}
|
2008-01-03 02:34:11 +01:00
|
|
|
|
2013-05-20 21:36:29 +02:00
|
|
|
if ( is_multisite() ) {
|
|
|
|
add_action( 'admin_footer', '_admin_notice_post_locked' );
|
|
|
|
} else {
|
|
|
|
$check_users = get_users( array( 'fields' => 'ID', 'number' => 2 ) );
|
|
|
|
|
|
|
|
if ( count( $check_users ) > 1 )
|
|
|
|
add_action( 'admin_footer', '_admin_notice_post_locked' );
|
|
|
|
|
|
|
|
unset( $check_users );
|
|
|
|
}
|
2013-03-12 04:22:30 +01:00
|
|
|
|
2010-05-11 21:52:50 +02:00
|
|
|
$title = $post_type_object->labels->edit_item;
|
2012-08-28 21:08:28 +02:00
|
|
|
$post = get_post($post_id, OBJECT, 'edit');
|
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();
|
|
|
|
}
|
|
|
|
|
2013-09-25 02:18:11 +02:00
|
|
|
include( ABSPATH . 'wp-admin/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':
|
2012-08-14 20:39:15 +02:00
|
|
|
check_admin_referer('update-post_' . $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':
|
2012-08-14 20:39:15 +02:00
|
|
|
check_admin_referer('update-post_' . $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
|
|
|
|
2013-03-14 04:06:07 +01:00
|
|
|
// Session cookie flag that the post was saved
|
2014-08-22 02:25:16 +02:00
|
|
|
if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) {
|
2015-09-11 00:42:23 +02:00
|
|
|
setcookie( 'wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, is_ssl() );
|
2014-08-22 02:25:16 +02:00
|
|
|
}
|
2013-03-14 04:06:07 +01: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-06 01:34:41 +01:00
|
|
|
|
2009-07-30 15:39:34 +02:00
|
|
|
case 'trash':
|
2012-08-14 20:39:15 +02:00
|
|
|
check_admin_referer('trash-post_' . $post_id);
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2013-05-08 20:56:54 +02:00
|
|
|
if ( ! $post )
|
|
|
|
wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ) );
|
|
|
|
|
|
|
|
if ( ! $post_type_object )
|
2017-01-10 03:40:42 +01:00
|
|
|
wp_die( __( 'Invalid post type.' ) );
|
2013-05-08 20:56:54 +02:00
|
|
|
|
2013-07-08 22:05:42 +02:00
|
|
|
if ( ! current_user_can( 'delete_post', $post_id ) )
|
2016-06-29 17:16:29 +02:00
|
|
|
wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2013-03-12 04:22:30 +01:00
|
|
|
if ( $user_id = wp_check_post_lock( $post_id ) ) {
|
|
|
|
$user = get_userdata( $user_id );
|
|
|
|
wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ) );
|
|
|
|
}
|
|
|
|
|
2013-05-08 20:56:54 +02:00
|
|
|
if ( ! wp_trash_post( $post_id ) )
|
|
|
|
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();
|
|
|
|
|
|
|
|
case 'untrash':
|
2012-08-14 20:39:15 +02:00
|
|
|
check_admin_referer('untrash-post_' . $post_id);
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2013-05-08 20:56:54 +02:00
|
|
|
if ( ! $post )
|
|
|
|
wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ) );
|
|
|
|
|
|
|
|
if ( ! $post_type_object )
|
2017-01-10 03:40:42 +01:00
|
|
|
wp_die( __( 'Invalid post type.' ) );
|
2009-07-30 15:39:34 +02:00
|
|
|
|
2013-07-08 22:05:42 +02:00
|
|
|
if ( ! current_user_can( 'delete_post', $post_id ) )
|
2016-06-29 17:16:29 +02:00
|
|
|
wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) );
|
2013-05-08 20:56:54 +02:00
|
|
|
|
|
|
|
if ( ! wp_untrash_post( $post_id ) )
|
|
|
|
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();
|
|
|
|
|
2004-04-28 06:49:16 +02:00
|
|
|
case 'delete':
|
2012-08-14 20:39:15 +02:00
|
|
|
check_admin_referer('delete-post_' . $post_id);
|
2005-12-13 20:19:56 +01:00
|
|
|
|
2013-05-08 20:56:54 +02:00
|
|
|
if ( ! $post )
|
|
|
|
wp_die( __( 'This item has already been deleted.' ) );
|
|
|
|
|
|
|
|
if ( ! $post_type_object )
|
2017-01-10 03:40:42 +01:00
|
|
|
wp_die( __( 'Invalid post type.' ) );
|
2013-05-08 20:56:54 +02:00
|
|
|
|
2013-07-08 22:05:42 +02:00
|
|
|
if ( ! current_user_can( 'delete_post', $post_id ) )
|
2016-06-29 17:16:29 +02:00
|
|
|
wp_die( __( 'Sorry, you are not allowed to delete this item.' ) );
|
2004-04-28 06:49:16 +02:00
|
|
|
|
2006-02-09 11:03:48 +01:00
|
|
|
if ( $post->post_type == 'attachment' ) {
|
2015-10-03 03:50:25 +02:00
|
|
|
$force = ( ! MEDIA_TRASH );
|
2013-05-08 20:56:54 +02:00
|
|
|
if ( ! wp_delete_attachment( $post_id, $force ) )
|
|
|
|
wp_die( __( 'Error in deleting.' ) );
|
2005-12-15 23:26:22 +01:00
|
|
|
} else {
|
2015-10-03 03:50:25 +02:00
|
|
|
if ( ! wp_delete_post( $post_id, true ) )
|
2013-05-08 20:56:54 +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();
|
2004-04-28 06:49:16 +02:00
|
|
|
|
2008-10-31 23:47:07 +01:00
|
|
|
case 'preview':
|
2014-01-22 05:56:16 +01:00
|
|
|
check_admin_referer( 'update-post_' . $post_id );
|
2008-10-31 23:47:07 +01:00
|
|
|
|
2008-11-04 14:00:12 +01:00
|
|
|
$url = post_preview();
|
2008-10-31 23:47:07 +01:00
|
|
|
|
|
|
|
wp_redirect($url);
|
|
|
|
exit();
|
|
|
|
|
2004-04-28 06:49:16 +02:00
|
|
|
default:
|
2016-05-12 17:44:28 +02:00
|
|
|
/**
|
|
|
|
* Fires for a given custom post action request.
|
|
|
|
*
|
|
|
|
* The dynamic portion of the hook name, `$action`, refers to the custom post action.
|
|
|
|
*
|
|
|
|
* @since 4.6.0
|
|
|
|
*
|
|
|
|
* @param int $post_id Post ID sent with the request.
|
|
|
|
*/
|
|
|
|
do_action( "post_action_{$action}", $post_id );
|
|
|
|
|
2010-12-09 19:02:54 +01:00
|
|
|
wp_redirect( admin_url('edit.php') );
|
2006-04-04 02:12:43 +02:00
|
|
|
exit();
|
2003-10-26 21:34:24 +01:00
|
|
|
} // end switch
|
2013-09-25 02:18:11 +02:00
|
|
|
include( ABSPATH . 'wp-admin/admin-footer.php' );
|