| 1 |
<?php |
| 2 |
/** |
| 3 |
* Edit item administration panel. |
| 4 |
* |
| 5 |
* Manage Item actions: post, edit, delete, etc. |
| 6 |
* |
| 7 |
* @package Welcart |
| 8 |
*/ |
| 9 |
|
| 10 |
global $wp_version; |
| 11 |
|
| 12 |
wp_reset_vars( |
| 13 |
array( |
| 14 |
'action', |
| 15 |
'safe_mode', |
| 16 |
'withcomments', |
| 17 |
'posts', |
| 18 |
'content', |
| 19 |
'edited_post_title', |
| 20 |
'comment_error', |
| 21 |
'profile', |
| 22 |
'trackback_url', |
| 23 |
'excerpt', |
| 24 |
'showcomments', |
| 25 |
'commentstart', |
| 26 |
'commentend', |
| 27 |
'commentorder', |
| 28 |
) |
| 29 |
); |
| 30 |
|
| 31 |
/** |
| 32 |
* Redirect to previous page. |
| 33 |
* |
| 34 |
* @param int $post_ID Optional. Post ID. |
| 35 |
*/ |
| 36 |
if ( ! function_exists( 'redirect_post' ) ) { |
| 37 |
|
| 38 |
function redirect_post( $post_ID = '' ) { |
| 39 |
global $action; |
| 40 |
|
| 41 |
$referredby = ''; |
| 42 |
if ( ! empty( $_POST['referredby'] ) ) { |
| 43 |
$referredby = preg_replace( '|https?://[^/]+|i', '', $_POST['referredby'] ); |
| 44 |
$referredby = remove_query_arg( '_wp_original_http_referer', $referredby ); |
| 45 |
} |
| 46 |
$referer = preg_replace( '|https?://[^/]+|i', '', wp_get_referer() ); |
| 47 |
|
| 48 |
if ( ! empty( $_POST['mode'] ) && 'bookmarklet' == $_POST['mode'] ) { |
| 49 |
$location = $_POST['referredby']; |
| 50 |
} elseif ( ! empty( $_POST['mode'] ) && 'sidebar' == $_POST['mode'] ) { |
| 51 |
if ( isset( $_POST['saveasdraft'] ) ) { |
| 52 |
$location = 'sidebar.php?a=c'; |
| 53 |
} elseif ( isset( $_POST['publish'] ) ) { |
| 54 |
$location = 'sidebar.php?a=b'; |
| 55 |
} |
| 56 |
} elseif ( ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) && ( empty( $referredby ) || $referredby == $referer || 'redo' != $referredby ) ) { |
| 57 |
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 ) { |
| 58 |
$location = add_query_arg( |
| 59 |
array( |
| 60 |
'_wp_original_http_referer' => urlencode( stripslashes( $_POST['_wp_original_http_referer'] ) ), |
| 61 |
'message' => 1, |
| 62 |
), |
| 63 |
usces_link_replace( get_edit_post_link( $post_ID, 'url' ) ) |
| 64 |
); |
| 65 |
} else { |
| 66 |
if ( isset( $_POST['publish'] ) ) { |
| 67 |
if ( 'pending' == get_post_status( $post_ID ) ) { |
| 68 |
$location = add_query_arg( 'message', 8, usces_link_replace( get_edit_post_link( $post_ID, 'url' ) ) ); |
| 69 |
} else { |
| 70 |
$location = add_query_arg( 'message', 6, usces_link_replace( get_edit_post_link( $post_ID, 'url' ) ) ); |
| 71 |
} |
| 72 |
} else { |
| 73 |
$location = add_query_arg( 'message', 7, usces_link_replace( get_edit_post_link( $post_ID, 'url' ) ) ); |
| 74 |
} |
| 75 |
} |
| 76 |
} elseif ( isset( $_POST['addmeta']) && $_POST['addmeta'] ) { |
| 77 |
$location = add_query_arg( 'message', 2, wp_get_referer() ); |
| 78 |
$location = explode( '#', $location ); |
| 79 |
$location = $location[0] . '#postcustom'; |
| 80 |
} elseif ( isset( $_POST['deletemeta'] ) && $_POST['deletemeta'] ) { |
| 81 |
$location = add_query_arg( 'message', 3, wp_get_referer() ); |
| 82 |
$location = explode( '#', $location ); |
| 83 |
$location = $location[0] . '#postcustom'; |
| 84 |
} elseif ( ! empty( $referredby ) && $referredby != $referer ) { |
| 85 |
$location = $_POST['referredby']; |
| 86 |
$location = remove_query_arg( '_wp_original_http_referer', $location ); |
| 87 |
if ( false !== strpos( $location, 'edit.php' ) || false !== strpos( $location, 'edit-post-drafts.php' ) ) { |
| 88 |
$location = add_query_arg('posted', $post_ID, $location); |
| 89 |
} elseif ( false !== strpos( $location, 'wp-admin' ) ) { |
| 90 |
$location = "post-new.php?posted=$post_ID"; |
| 91 |
} |
| 92 |
} elseif ( isset( $_POST['publish'] ) ) { |
| 93 |
$location = "post-new.php?posted=$post_ID"; |
| 94 |
} elseif ( 'editattachment' === $action ) { |
| 95 |
$location = 'attachments.php'; |
| 96 |
} elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) { |
| 97 |
$location = "post.php?action=edit&post=$post_ID&message=7"; |
| 98 |
} else { |
| 99 |
$location = add_query_arg( 'message', 4, usces_link_replace( get_edit_post_link( $post_ID, 'url' ) ) ); |
| 100 |
} |
| 101 |
wp_redirect( $location ); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
function usces_get_message( $post_ID ) { |
| 106 |
global $usces; |
| 107 |
|
| 108 |
if ( ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) ) { |
| 109 |
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 ) { |
| 110 |
$usces->action_message = sprintf( __( 'Post updated. <a href="%s">View post</a>' ), get_permalink( $post_ID ) ); |
| 111 |
} else { |
| 112 |
if ( isset( $_POST['publish'] ) ) { |
| 113 |
if ( 'pending' == get_post_status( $post_ID ) ) { |
| 114 |
$usces->action_message = sprintf( __( 'Post submitted. <a href="%s">Preview post</a>' ), add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ); |
| 115 |
} else { |
| 116 |
$usces->action_message = sprintf( __( 'Post published. <a href="%s">View post</a>'), get_permalink( $post_ID ) ); |
| 117 |
} |
| 118 |
} else { |
| 119 |
$usces->action_message = __( 'Post saved.' ); |
| 120 |
} |
| 121 |
} |
| 122 |
} elseif ( isset( $_POST['addmeta'] ) && $_POST['addmeta'] ) { |
| 123 |
$usces->action_message = __( 'Custom field updated.' ); |
| 124 |
} elseif ( isset( $_POST['deletemeta'] ) && $_POST['deletemeta'] ) { |
| 125 |
$usces->action_message = __( 'Custom field deleted.' ); |
| 126 |
} elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) { |
| 127 |
$usces->action_message = __( 'Post saved.' ); |
| 128 |
} else { |
| 129 |
$usces->action_message = __( 'Post updated.' ); |
| 130 |
} |
| 131 |
|
| 132 |
$usces->action_status = 'none'; |
| 133 |
} |
| 134 |
|
| 135 |
if ( isset( $_POST['deletepost'] ) ) { |
| 136 |
$action = 'delete'; |
| 137 |
} |
| 138 |
|
| 139 |
switch ( $action ) { |
| 140 |
|
| 141 |
case 'post': |
| 142 |
case 'edit': |
| 143 |
$editing = true; |
| 144 |
|
| 145 |
if ( empty( $_GET['post'] ) ) { |
| 146 |
wp_redirect( 'post.php' ); |
| 147 |
exit(); |
| 148 |
} |
| 149 |
|
| 150 |
$title = 'Welcart Shop ' . __( 'Edit item', 'usces' ); |
| 151 |
|
| 152 |
$this->action_status = 'none'; |
| 153 |
|
| 154 |
global $post; |
| 155 |
if ( $post ) { |
| 156 |
$post_type_object = get_post_type_object( $post->post_type ); |
| 157 |
if ( $post_type_object ) { |
| 158 |
$post_type = $post->post_type; |
| 159 |
if ( ! isset( $current_screen ) ) { |
| 160 |
$current_screen = new stdClass(); |
| 161 |
} |
| 162 |
$current_screen->post_type = $post->post_type; |
| 163 |
$current_screen->id = $current_screen->post_type; |
| 164 |
} |
| 165 |
$post_id = $post->ID; |
| 166 |
$post_ID = $post->ID; |
| 167 |
} |
| 168 |
|
| 169 |
$p = $post_id; |
| 170 |
|
| 171 |
if ( empty( $post->ID ) ) { |
| 172 |
wp_die( __( 'You attempted to edit an item that doesn’t exist. Perhaps it was deleted?' ) ); |
| 173 |
} |
| 174 |
|
| 175 |
if ( ! current_user_can( $post_type_object->cap->edit_post, $post_id ) ) { |
| 176 |
wp_die( __( 'You are not allowed to edit this item.' ) ); |
| 177 |
} |
| 178 |
|
| 179 |
if ( 'trash' == $post->post_status ) { |
| 180 |
wp_die( __( 'You can’t edit this item because it is in the Trash. Please restore it and try again.' ) ); |
| 181 |
} |
| 182 |
|
| 183 |
if ( null == $post_type_object ) { |
| 184 |
wp_die( __( 'Unknown post type.' ) ); |
| 185 |
} |
| 186 |
|
| 187 |
$post_type = $post->post_type; |
| 188 |
|
| 189 |
include USCES_PLUGIN_DIR . '/includes/edit-form-advanced34.php'; |
| 190 |
break; |
| 191 |
|
| 192 |
case 'editpost': |
| 193 |
|
| 194 |
global $post; |
| 195 |
$title = 'Welcart Shop ' . __( 'Edit item', 'usces' ); |
| 196 |
|
| 197 |
if ( $post ) { |
| 198 |
$post_type_object = get_post_type_object( $post->post_type ); |
| 199 |
if ( $post_type_object ) { |
| 200 |
$post_type = $post->post_type; |
| 201 |
if ( ! isset( $current_screen ) ) { |
| 202 |
$current_screen = new stdClass(); |
| 203 |
} |
| 204 |
$current_screen->post_type = $post->post_type; |
| 205 |
$current_screen->id = $current_screen->post_type; |
| 206 |
} |
| 207 |
$post_id = $post->ID; |
| 208 |
$post_ID = $post->ID; |
| 209 |
} |
| 210 |
add_action( 'check_admin_referer', 'usces_update_check_admin' ); |
| 211 |
|
| 212 |
check_admin_referer( 'update-' . $post_type . '_' . $post_id ); |
| 213 |
$post_id = edit_post(); |
| 214 |
$post_ID = $post_id; |
| 215 |
|
| 216 |
$post = get_post( $post_id, OBJECT, 'edit' ); |
| 217 |
|
| 218 |
include USCES_PLUGIN_DIR . '/includes/edit-form-advanced34.php'; |
| 219 |
|
| 220 |
if ( ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) ) { |
| 221 |
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 ) { |
| 222 |
$this->action_message = sprintf( __( 'Post updated. <a href="%s">View post</a>' ), get_permalink( $post_ID ) ); |
| 223 |
} else { |
| 224 |
if ( isset( $_POST['publish'] ) ) { |
| 225 |
if ( 'pending' == get_post_status( $post_ID ) ) { |
| 226 |
$this->action_message = sprintf( __( 'Post submitted. <a href="%s">Preview post</a>' ), add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ); |
| 227 |
} else { |
| 228 |
$this->action_message = sprintf( __( 'Post published. <a href="%s">View post</a>' ), get_permalink( $post_ID ) ); |
| 229 |
} |
| 230 |
} else { |
| 231 |
$this->action_message = __( 'Post saved.' ); |
| 232 |
} |
| 233 |
} |
| 234 |
} elseif ( isset( $_POST['addmeta'] ) && $_POST['addmeta'] ) { |
| 235 |
$this->action_message = __( 'Custom field updated.' ); |
| 236 |
} elseif ( isset( $_POST['deletemeta'] ) && $_POST['deletemeta'] ) { |
| 237 |
$this->action_message = __( 'Custom field deleted.' ); |
| 238 |
} elseif ( 'post-quickpress-save-cont' == $_POST['action'] ) { |
| 239 |
$this->action_message = __( 'Post saved.' ); |
| 240 |
} else { |
| 241 |
$this->action_message = __( 'Post updated.' ); |
| 242 |
} |
| 243 |
$this->action_status = 'success'; |
| 244 |
break; |
| 245 |
|
| 246 |
case 'new': |
| 247 |
|
| 248 |
$title = 'Welcart Shop ' . __( 'Add New Item', 'usces' ); |
| 249 |
global $post; |
| 250 |
|
| 251 |
global $post_ID, $current_screen; |
| 252 |
if ( ! isset( $_GET['post_type'] ) ) { |
| 253 |
$post_type = 'post'; |
| 254 |
} elseif ( in_array( $_GET['post_type'], get_post_types( array( 'public' => true ) ) ) ) { |
| 255 |
$post_type = $_GET['post_type']; |
| 256 |
} else { |
| 257 |
wp_die( __( 'Invalid post type' ) ); |
| 258 |
} |
| 259 |
$action = 'post'; |
| 260 |
$post = get_default_post_to_edit( $post_type, true ); |
| 261 |
$post_ID = $post->ID; |
| 262 |
|
| 263 |
include USCES_PLUGIN_DIR . '/includes/edit-form-advanced34.php'; |
| 264 |
break; |
| 265 |
|
| 266 |
case 'delete': |
| 267 |
$post_id = ( isset( $_GET['post'] ) ) ? intval( $_GET['post'] ) : intval( $_POST['post_ID'] ); |
| 268 |
check_admin_referer( 'delete-post_' . $post_id ); |
| 269 |
|
| 270 |
$post = & get_post( $post_id ); |
| 271 |
|
| 272 |
if ( ! current_user_can( 'delete_post', $post_id ) ) { |
| 273 |
wp_die( __( 'You are not allowed to delete this post.' ) ); |
| 274 |
} |
| 275 |
|
| 276 |
if ( $post->post_type == 'attachment' ) { |
| 277 |
if ( ! wp_delete_attachment( $post_id ) ) { |
| 278 |
wp_die( __( 'Error in deleting...' ) ); |
| 279 |
} |
| 280 |
} else { |
| 281 |
if ( ! wp_delete_post( $post_id ) ) { |
| 282 |
wp_die( __( 'Error in deleting...' ) ); |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
$sendback = wp_get_referer(); |
| 287 |
if ( strpos( $sendback, 'admin.php' ) !== false ) { |
| 288 |
$sendback = admin_url( 'admin.php?page=usces_itemedit&deleted=1' ); |
| 289 |
} elseif ( strpos( $sendback, 'attachments.php') !== false ) { |
| 290 |
$sendback = admin_url( 'attachments.php' ); |
| 291 |
} else { |
| 292 |
$sendback = admin_url( 'admin.php?page=usces_itemedit&deleted=1' ); |
| 293 |
} |
| 294 |
exit; |
| 295 |
|
| 296 |
default: |
| 297 |
exit; |
| 298 |
} // end switch |
| 299 |
|