mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Edit post administration panel.
mp-wp_genesis 4 *
mp-wp_genesis 5 * Manage Post actions: post, edit, delete, etc.
mp-wp_genesis 6 *
mp-wp_genesis 7 * @package WordPress
mp-wp_genesis 8 * @subpackage Administration
mp-wp_genesis 9 */
mp-wp_genesis 10
mp-wp_genesis 11 /** WordPress Administration Bootstrap */
mp-wp_genesis 12 require_once('admin.php');
mp-wp_genesis 13
mp-wp_genesis 14 $parent_file = 'edit.php';
mp-wp_genesis 15 $submenu_file = 'edit.php';
mp-wp_genesis 16
mp-wp_genesis 17 wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder'));
mp-wp_genesis 18
mp-wp_genesis 19 /**
mp-wp_genesis 20 * Redirect to previous page.
mp-wp_genesis 21 *
mp-wp_genesis 22 * @param int $post_ID Optional. Post ID.
mp-wp_genesis 23 */
mp-wp_genesis 24 function redirect_post($post_ID = '') {
mp-wp_genesis 25 global $action;
mp-wp_genesis 26
mp-wp_genesis 27 $referredby = '';
mp-wp_genesis 28 if ( !empty($_POST['referredby']) ) {
mp-wp_genesis 29 $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
mp-wp_genesis 30 $referredby = remove_query_arg('_wp_original_http_referer', $referredby);
mp-wp_genesis 31 }
mp-wp_genesis 32 $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
mp-wp_genesis 33
mp-wp_genesis 34 if ( !empty($_POST['mode']) && 'bookmarklet' == $_POST['mode'] ) {
mp-wp_genesis 35 $location = $_POST['referredby'];
mp-wp_genesis 36 } elseif ( !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
mp-wp_genesis 37 if ( isset($_POST['saveasdraft']) )
mp-wp_genesis 38 $location = 'sidebar.php?a=c';
mp-wp_genesis 39 elseif ( isset($_POST['publish']) )
mp-wp_genesis 40 $location = 'sidebar.php?a=b';
mp-wp_genesis 41 } elseif ( ( isset($_POST['save']) || isset($_POST['publish']) ) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) {
mp-wp_genesis 42 if ( isset($_POST['_wp_original_http_referer']) && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/post.php') === false && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/post-new.php') === false )
mp-wp_genesis 43 $location = add_query_arg( array(
mp-wp_genesis 44 '_wp_original_http_referer' => urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ),
mp-wp_genesis 45 'message' => 1
mp-wp_genesis 46 ), get_edit_post_link( $post_ID, 'url' ) );
mp-wp_genesis 47 else {
mp-wp_genesis 48 if ( isset( $_POST['publish'] ) ) {
mp-wp_genesis 49 if ( 'pending' == get_post_status( $post_ID ) )
mp-wp_genesis 50 $location = add_query_arg( 'message', 8, get_edit_post_link( $post_ID, 'url' ) );
mp-wp_genesis 51 else
mp-wp_genesis 52 $location = add_query_arg( 'message', 6, get_edit_post_link( $post_ID, 'url' ) );
mp-wp_genesis 53 } else {
mp-wp_genesis 54 $location = add_query_arg( 'message', 7, get_edit_post_link( $post_ID, 'url' ) );
mp-wp_genesis 55 }
mp-wp_genesis 56 }
mp-wp_genesis 57 } elseif (isset($_POST['addmeta']) && $_POST['addmeta']) {
mp-wp_genesis 58 $location = add_query_arg( 'message', 2, wp_get_referer() );
mp-wp_genesis 59 $location = explode('#', $location);
mp-wp_genesis 60 $location = $location[0] . '#postcustom';
mp-wp_genesis 61 } elseif (isset($_POST['deletemeta']) && $_POST['deletemeta']) {
mp-wp_genesis 62 $location = add_query_arg( 'message', 3, wp_get_referer() );
mp-wp_genesis 63 $location = explode('#', $location);
mp-wp_genesis 64 $location = $location[0] . '#postcustom';
mp-wp_genesis 65 } elseif (!empty($referredby) && $referredby != $referer) {
mp-wp_genesis 66 $location = $_POST['referredby'];
mp-wp_genesis 67 $location = remove_query_arg('_wp_original_http_referer', $location);
mp-wp_genesis 68 if ( false !== strpos($location, 'edit.php') || false !== strpos($location, 'edit-post-drafts.php') )
mp-wp_genesis 69 $location = add_query_arg('posted', $post_ID, $location);
mp-wp_genesis 70 elseif ( false !== strpos($location, 'wp-admin') )
mp-wp_genesis 71 $location = "post-new.php?posted=$post_ID";
mp-wp_genesis 72 } elseif ( isset($_POST['publish']) ) {
mp-wp_genesis 73 $location = "post-new.php?posted=$post_ID";
mp-wp_genesis 74 } elseif ($action == 'editattachment') {
mp-wp_genesis 75 $location = 'attachments.php';
mp-wp_genesis 76 } elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) {
mp-wp_genesis 77 $location = "post.php?action=edit&post=$post_ID&message=7";
mp-wp_genesis 78 } else {
mp-wp_genesis 79 $location = add_query_arg( 'message', 4, get_edit_post_link( $post_ID, 'url' ) );
mp-wp_genesis 80 }
mp-wp_genesis 81
mp-wp_genesis 82 wp_redirect( $location );
mp-wp_genesis 83 }
mp-wp_genesis 84
mp-wp_genesis 85 if ( isset( $_POST['deletepost'] ) )
mp-wp_genesis 86 $action = 'delete';
mp-wp_genesis 87 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
mp-wp_genesis 88 $action = 'preview';
mp-wp_genesis 89
mp-wp_genesis 90 switch($action) {
mp-wp_genesis 91 case 'postajaxpost':
mp-wp_genesis 92 case 'post':
mp-wp_genesis 93 case 'post-quickpress-publish':
mp-wp_genesis 94 case 'post-quickpress-save':
mp-wp_genesis 95 check_admin_referer('add-post');
mp-wp_genesis 96
mp-wp_genesis 97 if ( 'post-quickpress-publish' == $action )
mp-wp_genesis 98 $_POST['publish'] = 'publish'; // tell write_post() to publish
mp-wp_genesis 99
mp-wp_genesis 100 if ( 'post-quickpress-publish' == $action || 'post-quickpress-save' == $action ) {
mp-wp_genesis 101 $_POST['comment_status'] = get_option('default_comment_status');
mp-wp_genesis 102 $_POST['ping_status'] = get_option('default_ping_status');
mp-wp_genesis 103 }
mp-wp_genesis 104
mp-wp_genesis 105 if ( !empty( $_POST['quickpress_post_ID'] ) ) {
mp-wp_genesis 106 $_POST['post_ID'] = (int) $_POST['quickpress_post_ID'];
mp-wp_genesis 107 $post_ID = edit_post();
mp-wp_genesis 108 } else {
mp-wp_genesis 109 $post_ID = 'postajaxpost' == $action ? edit_post() : write_post();
mp-wp_genesis 110 }
mp-wp_genesis 111
mp-wp_genesis 112 if ( 0 === strpos( $action, 'post-quickpress' ) ) {
mp-wp_genesis 113 $_POST['post_ID'] = $post_ID;
mp-wp_genesis 114 // output the quickpress dashboard widget
mp-wp_genesis 115 require_once(ABSPATH . 'wp-admin/includes/dashboard.php');
mp-wp_genesis 116 wp_dashboard_quick_press();
mp-wp_genesis 117 exit;
mp-wp_genesis 118 }
mp-wp_genesis 119
mp-wp_genesis 120 redirect_post($post_ID);
mp-wp_genesis 121 exit();
mp-wp_genesis 122 break;
mp-wp_genesis 123
mp-wp_genesis 124 case 'edit':
mp-wp_genesis 125 $editing = true;
mp-wp_genesis 126
mp-wp_genesis 127 if ( empty( $_GET['post'] ) ) {
mp-wp_genesis 128 wp_redirect("post.php");
mp-wp_genesis 129 exit();
mp-wp_genesis 130 }
mp-wp_genesis 131 $post_ID = $p = (int) $_GET['post'];
mp-wp_genesis 132 $post = get_post($post_ID);
mp-wp_genesis 133
mp-wp_genesis 134 if ( empty($post->ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") );
mp-wp_genesis 135
mp-wp_genesis 136 if ( 'post' != $post->post_type ) {
mp-wp_genesis 137 wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
mp-wp_genesis 138 exit();
mp-wp_genesis 139 }
mp-wp_genesis 140
mp-wp_genesis 141 wp_enqueue_script('post');
mp-wp_genesis 142 add_thickbox();
mp-wp_genesis 143 wp_enqueue_script('media-upload');
mp-wp_genesis 144 wp_enqueue_script('word-count');
mp-wp_genesis 145 wp_enqueue_script( 'admin-comments' );
mp-wp_genesis 146 enqueue_comment_hotkeys_js();
mp-wp_genesis 147
mp-wp_genesis 148 if ( current_user_can('edit_post', $post_ID) ) {
mp-wp_genesis 149 if ( $last = wp_check_post_lock( $post->ID ) ) {
mp-wp_genesis 150 $last_user = get_userdata( $last );
mp-wp_genesis 151 $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
mp-wp_genesis 152 $message = sprintf( __( 'Warning: %s is currently editing this post' ), wp_specialchars( $last_user_name ) );
mp-wp_genesis 153 $message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
mp-wp_genesis 154 add_action('admin_notices', create_function( '', "echo '$message';" ) );
mp-wp_genesis 155 } else {
mp-wp_genesis 156 wp_set_post_lock( $post->ID );
mp-wp_genesis 157 wp_enqueue_script('autosave');
mp-wp_genesis 158 }
mp-wp_genesis 159 }
mp-wp_genesis 160
mp-wp_genesis 161 $title = __('Edit Post');
mp-wp_genesis 162
mp-wp_genesis 163 if ( !current_user_can('edit_post', $post_ID) )
mp-wp_genesis 164 die ( __('You are not allowed to edit this post.') );
mp-wp_genesis 165
mp-wp_genesis 166 $post = get_post_to_edit($post_ID);
mp-wp_genesis 167
mp-wp_genesis 168 include('edit-form-advanced.php');
mp-wp_genesis 169
mp-wp_genesis 170 break;
mp-wp_genesis 171
mp-wp_genesis 172 case 'editattachment':
mp-wp_genesis 173 $post_id = (int) $_POST['post_ID'];
mp-wp_genesis 174
mp-wp_genesis 175 check_admin_referer('update-attachment_' . $post_id);
mp-wp_genesis 176
mp-wp_genesis 177 // Don't let these be changed
mp-wp_genesis 178 unset($_POST['guid']);
mp-wp_genesis 179 $_POST['post_type'] = 'attachment';
mp-wp_genesis 180
mp-wp_genesis 181 // Update the thumbnail filename
mp-wp_genesis 182 $newmeta = wp_get_attachment_metadata( $post_id, true );
mp-wp_genesis 183 $newmeta['thumb'] = $_POST['thumb'];
mp-wp_genesis 184
mp-wp_genesis 185 wp_update_attachment_metadata( $post_id, $newmeta );
mp-wp_genesis 186
mp-wp_genesis 187 case 'editpost':
mp-wp_genesis 188 $post_ID = (int) $_POST['post_ID'];
mp-wp_genesis 189 check_admin_referer('update-post_' . $post_ID);
mp-wp_genesis 190
mp-wp_genesis 191 $post_ID = edit_post();
mp-wp_genesis 192
mp-wp_genesis 193 redirect_post($post_ID); // Send user on their way while we keep working
mp-wp_genesis 194
mp-wp_genesis 195 exit();
mp-wp_genesis 196 break;
mp-wp_genesis 197
mp-wp_genesis 198 case 'delete':
mp-wp_genesis 199 $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
mp-wp_genesis 200 check_admin_referer('delete-post_' . $post_id);
mp-wp_genesis 201
mp-wp_genesis 202 $post = & get_post($post_id);
mp-wp_genesis 203
mp-wp_genesis 204 if ( !current_user_can('delete_post', $post_id) )
mp-wp_genesis 205 wp_die( __('You are not allowed to delete this post.') );
mp-wp_genesis 206
mp-wp_genesis 207 if ( $post->post_type == 'attachment' ) {
mp-wp_genesis 208 if ( ! wp_delete_attachment($post_id) )
mp-wp_genesis 209 wp_die( __('Error in deleting...') );
mp-wp_genesis 210 } else {
mp-wp_genesis 211 if ( !wp_delete_post($post_id) )
mp-wp_genesis 212 wp_die( __('Error in deleting...') );
mp-wp_genesis 213 }
mp-wp_genesis 214
mp-wp_genesis 215 $sendback = wp_get_referer();
mp-wp_genesis 216 if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?deleted=1');
mp-wp_genesis 217 elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
mp-wp_genesis 218 else $sendback = add_query_arg('deleted', 1, $sendback);
mp-wp_genesis 219 wp_redirect($sendback);
mp-wp_genesis 220 exit();
mp-wp_genesis 221 break;
mp-wp_genesis 222
mp-wp_genesis 223 case 'preview':
mp-wp_genesis 224 check_admin_referer( 'autosave', 'autosavenonce' );
mp-wp_genesis 225
mp-wp_genesis 226 $url = post_preview();
mp-wp_genesis 227
mp-wp_genesis 228 wp_redirect($url);
mp-wp_genesis 229 exit();
mp-wp_genesis 230 break;
mp-wp_genesis 231
mp-wp_genesis 232 default:
mp-wp_genesis 233 wp_redirect('edit.php');
mp-wp_genesis 234 exit();
mp-wp_genesis 235 break;
mp-wp_genesis 236 } // end switch
mp-wp_genesis 237 include('admin-footer.php');
mp-wp_genesis 238 ?>