raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Edit page administration panel.
mp-wp_genesis 4 *
mp-wp_genesis 5 * Manage edit page: 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-pages.php';
mp-wp_genesis 15 $submenu_file = 'edit-pages.php';
mp-wp_genesis 16
mp-wp_genesis 17 wp_reset_vars(array('action'));
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 $page_ID Page ID.
mp-wp_genesis 23 */
mp-wp_genesis 24 function redirect_page($page_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 ( 'post' == $_POST['originalaction'] && !empty($_POST['mode']) && 'bookmarklet' == $_POST['mode'] ) {
mp-wp_genesis 35 $location = $_POST['referredby'];
mp-wp_genesis 36 } elseif ( 'post' == $_POST['originalaction'] && !empty($_POST['mode']) && 'sidebar' == $_POST['mode'] ) {
mp-wp_genesis 37 $location = 'sidebar.php?a=b';
mp-wp_genesis 38 } elseif ( ( isset($_POST['save']) || isset($_POST['publish']) ) && ( empty($referredby) || $referredby == $referer || 'redo' != $referredby ) ) {
mp-wp_genesis 39 if ( isset($_POST['_wp_original_http_referer']) && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/page.php') === false && strpos( $_POST['_wp_original_http_referer'], '/wp-admin/page-new.php') === false )
mp-wp_genesis 40 $location = add_query_arg( array(
mp-wp_genesis 41 '_wp_original_http_referer' => urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ),
mp-wp_genesis 42 'message' => 1
mp-wp_genesis 43 ), get_edit_post_link( $page_ID, 'url' ) );
mp-wp_genesis 44 else {
mp-wp_genesis 45 if ( isset( $_POST['publish'] ) ) {
mp-wp_genesis 46 if ( 'pending' == get_post_status( $page_ID ) )
mp-wp_genesis 47 $location = add_query_arg( 'message', 6, get_edit_post_link( $page_ID, 'url' ) );
mp-wp_genesis 48 else
mp-wp_genesis 49 $location = add_query_arg( 'message', 5, get_edit_post_link( $page_ID, 'url' ) );
mp-wp_genesis 50 } else {
mp-wp_genesis 51 $location = add_query_arg( 'message', 4, get_edit_post_link( $page_ID, 'url' ) );
mp-wp_genesis 52 }
mp-wp_genesis 53 }
mp-wp_genesis 54 } elseif ( isset($_POST['addmeta']) ) {
mp-wp_genesis 55 $location = add_query_arg( 'message', 2, wp_get_referer() );
mp-wp_genesis 56 $location = explode('#', $location);
mp-wp_genesis 57 $location = $location[0] . '#postcustom';
mp-wp_genesis 58 } elseif ( isset($_POST['deletemeta']) ) {
mp-wp_genesis 59 $location = add_query_arg( 'message', 3, wp_get_referer() );
mp-wp_genesis 60 $location = explode('#', $location);
mp-wp_genesis 61 $location = $location[0] . '#postcustom';
mp-wp_genesis 62 } elseif (!empty($referredby) && $referredby != $referer) {
mp-wp_genesis 63 $location = $_POST['referredby'];
mp-wp_genesis 64 $location = remove_query_arg('_wp_original_http_referer', $location);
mp-wp_genesis 65 if ( false !== strpos($location, 'edit-pages.php') )
mp-wp_genesis 66 $location = add_query_arg('posted', $page_ID, $location);
mp-wp_genesis 67 elseif ( false !== strpos($location, 'wp-admin') )
mp-wp_genesis 68 $location = "page-new.php?posted=$page_ID";
mp-wp_genesis 69 } elseif ( isset($_POST['publish']) ) {
mp-wp_genesis 70 $location = "page-new.php?posted=$page_ID";
mp-wp_genesis 71 } elseif ($action == 'editattachment') {
mp-wp_genesis 72 $location = 'attachments.php';
mp-wp_genesis 73 } else {
mp-wp_genesis 74 $location = add_query_arg( 'message', 4, get_edit_post_link( $page_ID, 'url' ) );
mp-wp_genesis 75 }
mp-wp_genesis 76
mp-wp_genesis 77 wp_redirect($location);
mp-wp_genesis 78 }
mp-wp_genesis 79
mp-wp_genesis 80 if (isset($_POST['deletepost']))
mp-wp_genesis 81 $action = "delete";
mp-wp_genesis 82 elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] )
mp-wp_genesis 83 $action = 'preview';
mp-wp_genesis 84
mp-wp_genesis 85 switch($action) {
mp-wp_genesis 86 case 'post':
mp-wp_genesis 87 check_admin_referer('add-page');
mp-wp_genesis 88 $page_ID = write_post();
mp-wp_genesis 89
mp-wp_genesis 90 redirect_page($page_ID);
mp-wp_genesis 91
mp-wp_genesis 92 exit();
mp-wp_genesis 93 break;
mp-wp_genesis 94
mp-wp_genesis 95 case 'edit':
mp-wp_genesis 96 $title = __('Edit Page');
mp-wp_genesis 97 $editing = true;
mp-wp_genesis 98 $page_ID = $post_ID = $p = (int) $_GET['post'];
mp-wp_genesis 99 $post = get_post_to_edit($page_ID);
mp-wp_genesis 100
mp-wp_genesis 101 if ( empty($post->ID) ) wp_die( __("You attempted to edit a page that doesn't exist. Perhaps it was deleted?") );
mp-wp_genesis 102
mp-wp_genesis 103 if ( 'page' != $post->post_type ) {
mp-wp_genesis 104 wp_redirect( get_edit_post_link( $post_ID, 'url' ) );
mp-wp_genesis 105 exit();
mp-wp_genesis 106 }
mp-wp_genesis 107
mp-wp_genesis 108 if ( current_user_can('edit_page', $page_ID) ) {
mp-wp_genesis 109 if ( $last = wp_check_post_lock( $post->ID ) ) {
mp-wp_genesis 110 $last_user = get_userdata( $last );
mp-wp_genesis 111 $last_user_name = $last_user ? $last_user->display_name : __('Somebody');
mp-wp_genesis 112 $message = sprintf( __( 'Warning: %s is currently editing this page' ), wp_specialchars( $last_user_name ) );
mp-wp_genesis 113 $message = str_replace( "'", "\'", "<div class='error'><p>$message</p></div>" );
mp-wp_genesis 114 add_action('admin_notices', create_function( '', "echo '$message';" ) );
mp-wp_genesis 115 } else {
mp-wp_genesis 116 wp_set_post_lock( $post->ID );
mp-wp_genesis 117 }
mp-wp_genesis 118 }
mp-wp_genesis 119
mp-wp_genesis 120 if ( !current_user_can('edit_page', $page_ID) )
mp-wp_genesis 121 die ( __('You are not allowed to edit this page.') );
mp-wp_genesis 122
mp-wp_genesis 123 include('edit-page-form.php');
mp-wp_genesis 124 break;
mp-wp_genesis 125
mp-wp_genesis 126 case 'editattachment':
mp-wp_genesis 127 $page_id = $post_ID = (int) $_POST['post_ID'];
mp-wp_genesis 128 check_admin_referer('update-attachment_' . $page_id);
mp-wp_genesis 129
mp-wp_genesis 130 // Don't let these be changed
mp-wp_genesis 131 unset($_POST['guid']);
mp-wp_genesis 132 $_POST['post_type'] = 'attachment';
mp-wp_genesis 133
mp-wp_genesis 134 // Update the thumbnail filename
mp-wp_genesis 135 $newmeta = wp_get_attachment_metadata( $page_id, true );
mp-wp_genesis 136 $newmeta['thumb'] = $_POST['thumb'];
mp-wp_genesis 137
mp-wp_genesis 138 wp_update_attachment_metadata( $newmeta );
mp-wp_genesis 139
mp-wp_genesis 140 case 'editpost':
mp-wp_genesis 141 $page_ID = (int) $_POST['post_ID'];
mp-wp_genesis 142 check_admin_referer('update-page_' . $page_ID);
mp-wp_genesis 143
mp-wp_genesis 144 $page_ID = edit_post();
mp-wp_genesis 145
mp-wp_genesis 146 redirect_page($page_ID);
mp-wp_genesis 147
mp-wp_genesis 148 exit();
mp-wp_genesis 149 break;
mp-wp_genesis 150
mp-wp_genesis 151 case 'delete':
mp-wp_genesis 152 $page_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
mp-wp_genesis 153 check_admin_referer('delete-page_' . $page_id);
mp-wp_genesis 154
mp-wp_genesis 155 $page = & get_post($page_id);
mp-wp_genesis 156
mp-wp_genesis 157 if ( !current_user_can('delete_page', $page_id) )
mp-wp_genesis 158 wp_die( __('You are not allowed to delete this page.') );
mp-wp_genesis 159
mp-wp_genesis 160 if ( $page->post_type == 'attachment' ) {
mp-wp_genesis 161 if ( ! wp_delete_attachment($page_id) )
mp-wp_genesis 162 wp_die( __('Error in deleting...') );
mp-wp_genesis 163 } else {
mp-wp_genesis 164 if ( !wp_delete_post($page_id) )
mp-wp_genesis 165 wp_die( __('Error in deleting...') );
mp-wp_genesis 166 }
mp-wp_genesis 167
mp-wp_genesis 168 $sendback = wp_get_referer();
mp-wp_genesis 169 if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('edit-pages.php?deleted=1');
mp-wp_genesis 170 elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
mp-wp_genesis 171 else $sendback = add_query_arg('deleted', 1, $sendback);
mp-wp_genesis 172 wp_redirect($sendback);
mp-wp_genesis 173 exit();
mp-wp_genesis 174 break;
mp-wp_genesis 175
mp-wp_genesis 176 case 'preview':
mp-wp_genesis 177 check_admin_referer( 'autosave', 'autosavenonce' );
mp-wp_genesis 178
mp-wp_genesis 179 $url = post_preview();
mp-wp_genesis 180
mp-wp_genesis 181 wp_redirect($url);
mp-wp_genesis 182 exit();
mp-wp_genesis 183 break;
mp-wp_genesis 184
mp-wp_genesis 185 default:
mp-wp_genesis 186 wp_redirect('edit-pages.php');
mp-wp_genesis 187 exit();
mp-wp_genesis 188 break;
mp-wp_genesis 189 } // end switch
mp-wp_genesis 190 include('admin-footer.php');
mp-wp_genesis 191 ?>