PageRenderTime 63ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/post.php

https://github.com/alx/pressmark
PHP | 263 lines | 190 code | 56 blank | 17 comment | 50 complexity | cd7b1c6ad04396eaa1cefc47cba2d784 MD5 | raw file
  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('admin.php');
  12. $parent_file = 'edit.php';
  13. $submenu_file = 'edit.php';
  14. wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder'));
  15. /**
  16. * Redirect to previous page.
  17. *
  18. * @param int $post_ID Optional. Post ID.
  19. */
  20. function redirect_post($post_ID = '') {
  21. global $action;
  22. $referredby = '';
  23. if ( !empty($_POST['referredby']) ) {
  24. $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
  25. $referredby = remove_query_arg('_wp_original_http_referer', $referredby);
  26. }
  27. $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
  28. if ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
  29. if ( isset($_POST['saveasdraft']) )
  30. $location = 'sidebar.php?a=c';
  31. elseif ( isset($_POST['publish']) )
  32. $location = 'sidebar.php?a=b';
  33. } elseif ( isset($_POST['save']) || isset($_POST['publish']) ) {
  34. $status = get_post_status( $post_ID );
  35. if ( isset( $_POST['publish'] ) ) {
  36. switch ( $status ) {
  37. case 'pending':
  38. $message = 8;
  39. break;
  40. case 'future':
  41. $message = 9;
  42. break;
  43. default:
  44. $message = 6;
  45. }
  46. } else {
  47. $message = 'draft' == $status ? 10 : 1;
  48. }
  49. $location = add_query_arg( 'message', $message, get_edit_post_link( $post_ID, 'url' ) );
  50. } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) {
  51. $location = add_query_arg( 'message', 2, wp_get_referer() );
  52. $location = explode('#', $location);
  53. $location = $location[0] . '#postcustom';
  54. } elseif ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) {
  55. $location = add_query_arg( 'message', 3, wp_get_referer() );
  56. $location = explode('#', $location);
  57. $location = $location[0] . '#postcustom';
  58. } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
  59. $location = "post.php?action=edit&post=$post_ID&message=7";
  60. } else {
  61. $location = add_query_arg( 'message', 4, get_edit_post_link( $post_ID, 'url' ) );
  62. }
  63. wp_redirect( apply_filters( 'redirect_post_location', $location, $post_ID ) );
  64. }
  65. if ( isset( $_POST['deletepost'] ) )
  66. $action = 'delete';
  67. elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
  68. $action = 'preview';
  69. $sendback = wp_get_referer();
  70. if ( strpos($sendback, 'post.php') !== false || strpos($sendback, 'post-new.php') !== false )
  71. $sendback = admin_url('edit.php');
  72. else
  73. $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $sendback );
  74. switch($action) {
  75. case 'postajaxpost':
  76. case 'post':
  77. case 'post-quickpress-publish':
  78. case 'post-quickpress-save':
  79. check_admin_referer('add-post');
  80. if ( 'post-quickpress-publish' == $action )
  81. $_POST['publish'] = 'publish'; // tell write_post() to publish
  82. if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) {
  83. $_POST['comment_status'] = get_option('default_comment_status');
  84. $_POST['ping_status'] = get_option('default_ping_status');
  85. }
  86. if ( !empty( $_POST['quickpress_post_ID'] ) ) {
  87. $_POST['post_ID'] = (int) $_POST['quickpress_post_ID'];
  88. $post_ID = edit_post();
  89. } else {
  90. $post_ID = 'postajaxpost' == $action ? edit_post() : write_post();
  91. }
  92. if ( 0 === strpos( $action, 'post-quickpress' ) ) {
  93. $_POST['post_ID'] = $post_ID;
  94. // output the quickpress dashboard widget
  95. require_once(ABSPATH . 'wp-admin/includes/dashboard.php');
  96. wp_dashboard_quick_press();
  97. exit;
  98. }
  99. redirect_post($post_ID);
  100. exit();
  101. break;
  102. case 'edit':
  103. $editing = true;
  104. if ( empty( $_GET['post'] ) ) {
  105. wp_redirect("post.php");
  106. exit();
  107. }
  108. $post_ID = $p = (int) $_GET['post'];
  109. $post = get_post($post_ID);
  110. if ( empty($post->ID) )
  111. wp_die( __('You attempted to edit a post that doesn&#8217;t exist. Perhaps it was deleted?') );
  112. if ( !current_user_can('edit_post', $post_ID) )
  113. wp_die( __('You are not allowed to edit this post.') );
  114. if ( 'trash' == $post->post_status )
  115. wp_die( __('You can&#8217;t edit this post because it is in the Trash. Please restore it and try again.') );
  116. if ( 'post' != $post->post_type ) {
  117. wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
  118. exit();
  119. }
  120. wp_enqueue_script('post');
  121. if ( user_can_richedit() )
  122. wp_enqueue_script('editor');
  123. add_thickbox();
  124. wp_enqueue_script('media-upload');
  125. wp_enqueue_script('word-count');
  126. wp_enqueue_script( 'admin-comments' );
  127. enqueue_comment_hotkeys_js();
  128. if ( $last = wp_check_post_lock( $post->ID ) ) {
  129. add_action('admin_notices', '_admin_notice_post_locked' );
  130. } else {
  131. wp_set_post_lock( $post->ID );
  132. wp_enqueue_script('autosave');
  133. }
  134. $title = __('Edit Post');
  135. $post = get_post_to_edit($post_ID);
  136. include('edit-form-advanced.php');
  137. break;
  138. case 'editattachment':
  139. $post_id = (int) $_POST['post_ID'];
  140. check_admin_referer('update-attachment_' . $post_id);
  141. // Don't let these be changed
  142. unset($_POST['guid']);
  143. $_POST['post_type'] = 'attachment';
  144. // Update the thumbnail filename
  145. $newmeta = wp_get_attachment_metadata( $post_id, true );
  146. $newmeta['thumb'] = $_POST['thumb'];
  147. wp_update_attachment_metadata( $post_id, $newmeta );
  148. case 'editpost':
  149. $post_ID = (int) $_POST['post_ID'];
  150. check_admin_referer('update-post_' . $post_ID);
  151. $post_ID = edit_post();
  152. redirect_post($post_ID); // Send user on their way while we keep working
  153. exit();
  154. break;
  155. case 'trash':
  156. $post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);
  157. check_admin_referer('trash-post_' . $post_id);
  158. $post = & get_post($post_id);
  159. if ( !current_user_can('delete_post', $post_id) )
  160. wp_die( __('You are not allowed to move this post to the trash.') );
  161. if ( ! wp_trash_post($post_id) )
  162. wp_die( __('Error in moving to trash...') );
  163. wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
  164. exit();
  165. break;
  166. case 'untrash':
  167. $post_id = isset($_GET['post']) ? intval($_GET['post']) : intval($_POST['post_ID']);
  168. check_admin_referer('untrash-post_' . $post_id);
  169. $post = & get_post($post_id);
  170. if ( !current_user_can('delete_post', $post_id) )
  171. wp_die( __('You are not allowed to move this post out of the trash.') );
  172. if ( ! wp_untrash_post($post_id) )
  173. wp_die( __('Error in restoring from trash...') );
  174. wp_redirect( add_query_arg('untrashed', 1, $sendback) );
  175. exit();
  176. break;
  177. case 'delete':
  178. $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
  179. check_admin_referer('delete-post_' . $post_id);
  180. $post = & get_post($post_id);
  181. if ( !current_user_can('delete_post', $post_id) )
  182. wp_die( __('You are not allowed to delete this post.') );
  183. $force = !EMPTY_TRASH_DAYS;
  184. if ( $post->post_type == 'attachment' ) {
  185. $force = ( $force || !MEDIA_TRASH );
  186. if ( ! wp_delete_attachment($post_id, $force) )
  187. wp_die( __('Error in deleting...') );
  188. } else {
  189. if ( !wp_delete_post($post_id, $force) )
  190. wp_die( __('Error in deleting...') );
  191. }
  192. wp_redirect( add_query_arg('deleted', 1, $sendback) );
  193. exit();
  194. break;
  195. case 'preview':
  196. check_admin_referer( 'autosave', 'autosavenonce' );
  197. $url = post_preview();
  198. wp_redirect($url);
  199. exit();
  200. break;
  201. default:
  202. wp_redirect('edit.php');
  203. exit();
  204. break;
  205. } // end switch
  206. include('admin-footer.php');
  207. ?>