if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] ) { wp_die( __( 'A post ID mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 ); } elseif ( isset( $_GET['post'] ) ) { $post_id = (int) $_GET['post']; } elseif ( isset( $_POST['post_ID'] ) ) { $post_id = (int) $_POST['post_ID']; } else { $post_id = 0; } $post_ID = $post_id;
/** * @global string $post_type Global post type. * @global WP_Post_Type $post_type_object Global post type object. * @global WP_Post $post Global post object. */ global $post_type, $post_type_object, $post;
if ( isset( $_POST['post_type'] ) && $post && $post_type !== $_POST['post_type'] ) { wp_die( __( 'A post type mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 ); }
if ( ! $post ) { wp_die( __( 'You attempted to edit an item that does not exist. Perhaps it was deleted?' ) ); }
if ( ! $post_type_object ) { wp_die( __( 'Invalid post type.' ) ); }
if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ), true ) ) { wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); }
if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_die( __( 'Sorry, you are not allowed to edit this item.' ) ); }
if ( 'trash' === $post->post_status ) { wp_die( __( 'You cannot edit this item because it is in the Trash. Please restore it and try again.' ) ); }
default: /** * Fires for a given custom post action request. * * The dynamic portion of the hook name, `$action`, refers to the custom post action. * * @since 4.6.0 * * @param int $post_id Post ID sent with the request. */ do_action( "post_action_{$action}", $post_id );
wp_redirect( admin_url( 'edit.php' ) ); exit; } // End switch.