PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/public/wp-admin/post.php

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