You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

293 lines
8.0 KiB

  1. <?php
  2. /**
  3. * Edit post administration panel.
  4. *
  5. * Manage Post actions: post, edit, delete, etc.
  6. *
  7. * @package WordPress
  8. * @subpackage Administration
  9. */
  10. /** WordPress Administration Bootstrap */
  11. require_once( dirname( __FILE__ ) . '/admin.php' );
  12. $parent_file = 'edit.php';
  13. $submenu_file = 'edit.php';
  14. wp_reset_vars( array( 'action' ) );
  15. if ( isset( $_GET['post'] ) )
  16. $post_id = $post_ID = (int) $_GET['post'];
  17. elseif ( isset( $_POST['post_ID'] ) )
  18. $post_id = $post_ID = (int) $_POST['post_ID'];
  19. else
  20. $post_id = $post_ID = 0;
  21. /**
  22. * @global string $post_type
  23. * @global object $post_type_object
  24. * @global WP_Post $post
  25. */
  26. global $post_type, $post_type_object, $post;
  27. if ( $post_id )
  28. $post = get_post( $post_id );
  29. if ( $post ) {
  30. $post_type = $post->post_type;
  31. $post_type_object = get_post_type_object( $post_type );
  32. }
  33. if ( isset( $_POST['deletepost'] ) )
  34. $action = 'delete';
  35. elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
  36. $action = 'preview';
  37. $sendback = wp_get_referer();
  38. if ( ! $sendback ||
  39. strpos( $sendback, 'post.php' ) !== false ||
  40. strpos( $sendback, 'post-new.php' ) !== false ) {
  41. if ( 'attachment' == $post_type ) {
  42. $sendback = admin_url( 'upload.php' );
  43. } else {
  44. $sendback = admin_url( 'edit.php' );
  45. if ( ! empty( $post_type ) ) {
  46. $sendback = add_query_arg( 'post_type', $post_type, $sendback );
  47. }
  48. }
  49. } else {
  50. $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback );
  51. }
  52. switch($action) {
  53. case 'post-quickdraft-save':
  54. // Check nonce and capabilities
  55. $nonce = $_REQUEST['_wpnonce'];
  56. $error_msg = false;
  57. // For output of the quickdraft dashboard widget
  58. require_once ABSPATH . 'wp-admin/includes/dashboard.php';
  59. if ( ! wp_verify_nonce( $nonce, 'add-post' ) )
  60. $error_msg = __( 'Unable to submit this form, please refresh and try again.' );
  61. if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
  62. exit;
  63. }
  64. if ( $error_msg )
  65. return wp_dashboard_quick_press( $error_msg );
  66. $post = get_post( $_REQUEST['post_ID'] );
  67. check_admin_referer( 'add-' . $post->post_type );
  68. $_POST['comment_status'] = get_default_comment_status( $post->post_type );
  69. $_POST['ping_status'] = get_default_comment_status( $post->post_type, 'pingback' );
  70. edit_post();
  71. wp_dashboard_quick_press();
  72. exit;
  73. case 'postajaxpost':
  74. case 'post':
  75. check_admin_referer( 'add-' . $post_type );
  76. $post_id = 'postajaxpost' == $action ? edit_post() : write_post();
  77. redirect_post( $post_id );
  78. exit();
  79. case 'edit':
  80. $editing = true;
  81. if ( empty( $post_id ) ) {
  82. wp_redirect( admin_url('post.php') );
  83. exit();
  84. }
  85. if ( ! $post )
  86. wp_die( __( 'You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?' ) );
  87. if ( ! $post_type_object )
  88. wp_die( __( 'Unknown post type.' ) );
  89. if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ) ) ) {
  90. wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ) );
  91. }
  92. if ( ! current_user_can( 'edit_post', $post_id ) )
  93. wp_die( __( 'Sorry, you are not allowed to edit this item.' ) );
  94. if ( 'trash' == $post->post_status )
  95. wp_die( __( 'You can&#8217;t edit this item because it is in the Trash. Please restore it and try again.' ) );
  96. if ( ! empty( $_GET['get-post-lock'] ) ) {
  97. check_admin_referer( 'lock-post_' . $post_id );
  98. wp_set_post_lock( $post_id );
  99. wp_redirect( get_edit_post_link( $post_id, 'url' ) );
  100. exit();
  101. }
  102. $post_type = $post->post_type;
  103. if ( 'post' == $post_type ) {
  104. $parent_file = "edit.php";
  105. $submenu_file = "edit.php";
  106. $post_new_file = "post-new.php";
  107. } elseif ( 'attachment' == $post_type ) {
  108. $parent_file = 'upload.php';
  109. $submenu_file = 'upload.php';
  110. $post_new_file = 'media-new.php';
  111. } else {
  112. if ( isset( $post_type_object ) && $post_type_object->show_in_menu && $post_type_object->show_in_menu !== true )
  113. $parent_file = $post_type_object->show_in_menu;
  114. else
  115. $parent_file = "edit.php?post_type=$post_type";
  116. $submenu_file = "edit.php?post_type=$post_type";
  117. $post_new_file = "post-new.php?post_type=$post_type";
  118. }
  119. if ( ! wp_check_post_lock( $post->ID ) ) {
  120. $active_post_lock = wp_set_post_lock( $post->ID );
  121. if ( 'attachment' !== $post_type )
  122. wp_enqueue_script('autosave');
  123. }
  124. if ( is_multisite() ) {
  125. add_action( 'admin_footer', '_admin_notice_post_locked' );
  126. } else {
  127. $check_users = get_users( array( 'fields' => 'ID', 'number' => 2 ) );
  128. if ( count( $check_users ) > 1 )
  129. add_action( 'admin_footer', '_admin_notice_post_locked' );
  130. unset( $check_users );
  131. }
  132. $title = $post_type_object->labels->edit_item;
  133. $post = get_post($post_id, OBJECT, 'edit');
  134. if ( post_type_supports($post_type, 'comments') ) {
  135. wp_enqueue_script('admin-comments');
  136. enqueue_comment_hotkeys_js();
  137. }
  138. include( ABSPATH . 'wp-admin/edit-form-advanced.php' );
  139. break;
  140. case 'editattachment':
  141. check_admin_referer('update-post_' . $post_id);
  142. // Don't let these be changed
  143. unset($_POST['guid']);
  144. $_POST['post_type'] = 'attachment';
  145. // Update the thumbnail filename
  146. $newmeta = wp_get_attachment_metadata( $post_id, true );
  147. $newmeta['thumb'] = $_POST['thumb'];
  148. wp_update_attachment_metadata( $post_id, $newmeta );
  149. case 'editpost':
  150. check_admin_referer('update-post_' . $post_id);
  151. $post_id = edit_post();
  152. // Session cookie flag that the post was saved
  153. if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) {
  154. setcookie( 'wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, is_ssl() );
  155. }
  156. redirect_post($post_id); // Send user on their way while we keep working
  157. exit();
  158. case 'trash':
  159. check_admin_referer('trash-post_' . $post_id);
  160. if ( ! $post )
  161. wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ) );
  162. if ( ! $post_type_object )
  163. wp_die( __( 'Unknown post type.' ) );
  164. if ( ! current_user_can( 'delete_post', $post_id ) )
  165. wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
  166. if ( $user_id = wp_check_post_lock( $post_id ) ) {
  167. $user = get_userdata( $user_id );
  168. wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ) );
  169. }
  170. if ( ! wp_trash_post( $post_id ) )
  171. wp_die( __( 'Error in moving to Trash.' ) );
  172. wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
  173. exit();
  174. case 'untrash':
  175. check_admin_referer('untrash-post_' . $post_id);
  176. if ( ! $post )
  177. wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ) );
  178. if ( ! $post_type_object )
  179. wp_die( __( 'Unknown post type.' ) );
  180. if ( ! current_user_can( 'delete_post', $post_id ) )
  181. wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) );
  182. if ( ! wp_untrash_post( $post_id ) )
  183. wp_die( __( 'Error in restoring from Trash.' ) );
  184. wp_redirect( add_query_arg('untrashed', 1, $sendback) );
  185. exit();
  186. case 'delete':
  187. check_admin_referer('delete-post_' . $post_id);
  188. if ( ! $post )
  189. wp_die( __( 'This item has already been deleted.' ) );
  190. if ( ! $post_type_object )
  191. wp_die( __( 'Unknown post type.' ) );
  192. if ( ! current_user_can( 'delete_post', $post_id ) )
  193. wp_die( __( 'Sorry, you are not allowed to delete this item.' ) );
  194. if ( $post->post_type == 'attachment' ) {
  195. $force = ( ! MEDIA_TRASH );
  196. if ( ! wp_delete_attachment( $post_id, $force ) )
  197. wp_die( __( 'Error in deleting.' ) );
  198. } else {
  199. if ( ! wp_delete_post( $post_id, true ) )
  200. wp_die( __( 'Error in deleting.' ) );
  201. }
  202. wp_redirect( add_query_arg('deleted', 1, $sendback) );
  203. exit();
  204. case 'preview':
  205. check_admin_referer( 'update-post_' . $post_id );
  206. $url = post_preview();
  207. wp_redirect($url);
  208. exit();
  209. default:
  210. /**
  211. * Fires for a given custom post action request.
  212. *
  213. * The dynamic portion of the hook name, `$action`, refers to the custom post action.
  214. *
  215. * @since 4.6.0
  216. *
  217. * @param int $post_id Post ID sent with the request.
  218. */
  219. do_action( "post_action_{$action}", $post_id );
  220. wp_redirect( admin_url('edit.php') );
  221. exit();
  222. } // end switch
  223. include( ABSPATH . 'wp-admin/admin-footer.php' );