Edit File by line
/home/barbar84/www/wp-admin
File: post.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Edit post administration panel.
[2] Fix | Delete
*
[3] Fix | Delete
* Manage Post actions: post, edit, delete, etc.
[4] Fix | Delete
*
[5] Fix | Delete
* @package WordPress
[6] Fix | Delete
* @subpackage Administration
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
/** WordPress Administration Bootstrap */
[10] Fix | Delete
require_once __DIR__ . '/admin.php';
[11] Fix | Delete
[12] Fix | Delete
$parent_file = 'edit.php';
[13] Fix | Delete
$submenu_file = 'edit.php';
[14] Fix | Delete
[15] Fix | Delete
wp_reset_vars( array( 'action' ) );
[16] Fix | Delete
[17] Fix | Delete
if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] ) {
[18] Fix | Delete
wp_die( __( 'A post ID mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 );
[19] Fix | Delete
} elseif ( isset( $_GET['post'] ) ) {
[20] Fix | Delete
$post_id = (int) $_GET['post'];
[21] Fix | Delete
} elseif ( isset( $_POST['post_ID'] ) ) {
[22] Fix | Delete
$post_id = (int) $_POST['post_ID'];
[23] Fix | Delete
} else {
[24] Fix | Delete
$post_id = 0;
[25] Fix | Delete
}
[26] Fix | Delete
$post_ID = $post_id;
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* @global string $post_type
[30] Fix | Delete
* @global object $post_type_object
[31] Fix | Delete
* @global WP_Post $post Global post object.
[32] Fix | Delete
*/
[33] Fix | Delete
global $post_type, $post_type_object, $post;
[34] Fix | Delete
[35] Fix | Delete
if ( $post_id ) {
[36] Fix | Delete
$post = get_post( $post_id );
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
if ( $post ) {
[40] Fix | Delete
$post_type = $post->post_type;
[41] Fix | Delete
$post_type_object = get_post_type_object( $post_type );
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
if ( isset( $_POST['post_type'] ) && $post && $post_type !== $_POST['post_type'] ) {
[45] Fix | Delete
wp_die( __( 'A post type mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 );
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
if ( isset( $_POST['deletepost'] ) ) {
[49] Fix | Delete
$action = 'delete';
[50] Fix | Delete
} elseif ( isset( $_POST['wp-preview'] ) && 'dopreview' === $_POST['wp-preview'] ) {
[51] Fix | Delete
$action = 'preview';
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
$sendback = wp_get_referer();
[55] Fix | Delete
if ( ! $sendback ||
[56] Fix | Delete
false !== strpos( $sendback, 'post.php' ) ||
[57] Fix | Delete
false !== strpos( $sendback, 'post-new.php' ) ) {
[58] Fix | Delete
if ( 'attachment' === $post_type ) {
[59] Fix | Delete
$sendback = admin_url( 'upload.php' );
[60] Fix | Delete
} else {
[61] Fix | Delete
$sendback = admin_url( 'edit.php' );
[62] Fix | Delete
if ( ! empty( $post_type ) ) {
[63] Fix | Delete
$sendback = add_query_arg( 'post_type', $post_type, $sendback );
[64] Fix | Delete
}
[65] Fix | Delete
}
[66] Fix | Delete
} else {
[67] Fix | Delete
$sendback = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids' ), $sendback );
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
switch ( $action ) {
[71] Fix | Delete
case 'post-quickdraft-save':
[72] Fix | Delete
// Check nonce and capabilities.
[73] Fix | Delete
$nonce = $_REQUEST['_wpnonce'];
[74] Fix | Delete
$error_msg = false;
[75] Fix | Delete
[76] Fix | Delete
// For output of the Quick Draft dashboard widget.
[77] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/dashboard.php';
[78] Fix | Delete
[79] Fix | Delete
if ( ! wp_verify_nonce( $nonce, 'add-post' ) ) {
[80] Fix | Delete
$error_msg = __( 'Unable to submit this form, please refresh and try again.' );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
[84] Fix | Delete
exit;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
if ( $error_msg ) {
[88] Fix | Delete
return wp_dashboard_quick_press( $error_msg );
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
$post = get_post( $_REQUEST['post_ID'] );
[92] Fix | Delete
check_admin_referer( 'add-' . $post->post_type );
[93] Fix | Delete
[94] Fix | Delete
$_POST['comment_status'] = get_default_comment_status( $post->post_type );
[95] Fix | Delete
$_POST['ping_status'] = get_default_comment_status( $post->post_type, 'pingback' );
[96] Fix | Delete
[97] Fix | Delete
// Wrap Quick Draft content in the Paragraph block.
[98] Fix | Delete
if ( false === strpos( $_POST['content'], '<!-- wp:paragraph -->' ) ) {
[99] Fix | Delete
$_POST['content'] = sprintf(
[100] Fix | Delete
'<!-- wp:paragraph -->%s<!-- /wp:paragraph -->',
[101] Fix | Delete
str_replace( array( "\r\n", "\r", "\n" ), '<br />', $_POST['content'] )
[102] Fix | Delete
);
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
edit_post();
[106] Fix | Delete
wp_dashboard_quick_press();
[107] Fix | Delete
exit;
[108] Fix | Delete
[109] Fix | Delete
case 'postajaxpost':
[110] Fix | Delete
case 'post':
[111] Fix | Delete
check_admin_referer( 'add-' . $post_type );
[112] Fix | Delete
$post_id = 'postajaxpost' === $action ? edit_post() : write_post();
[113] Fix | Delete
redirect_post( $post_id );
[114] Fix | Delete
exit;
[115] Fix | Delete
[116] Fix | Delete
case 'edit':
[117] Fix | Delete
$editing = true;
[118] Fix | Delete
[119] Fix | Delete
if ( empty( $post_id ) ) {
[120] Fix | Delete
wp_redirect( admin_url( 'post.php' ) );
[121] Fix | Delete
exit;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
if ( ! $post ) {
[125] Fix | Delete
wp_die( __( 'You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?' ) );
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
if ( ! $post_type_object ) {
[129] Fix | Delete
wp_die( __( 'Invalid post type.' ) );
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ), true ) ) {
[133] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ) );
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
if ( ! current_user_can( 'edit_post', $post_id ) ) {
[137] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to edit this item.' ) );
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
if ( 'trash' === $post->post_status ) {
[141] Fix | Delete
wp_die( __( 'You can&#8217;t edit this item because it is in the Trash. Please restore it and try again.' ) );
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
if ( ! empty( $_GET['get-post-lock'] ) ) {
[145] Fix | Delete
check_admin_referer( 'lock-post_' . $post_id );
[146] Fix | Delete
wp_set_post_lock( $post_id );
[147] Fix | Delete
wp_redirect( get_edit_post_link( $post_id, 'url' ) );
[148] Fix | Delete
exit;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
$post_type = $post->post_type;
[152] Fix | Delete
if ( 'post' === $post_type ) {
[153] Fix | Delete
$parent_file = 'edit.php';
[154] Fix | Delete
$submenu_file = 'edit.php';
[155] Fix | Delete
$post_new_file = 'post-new.php';
[156] Fix | Delete
} elseif ( 'attachment' === $post_type ) {
[157] Fix | Delete
$parent_file = 'upload.php';
[158] Fix | Delete
$submenu_file = 'upload.php';
[159] Fix | Delete
$post_new_file = 'media-new.php';
[160] Fix | Delete
} else {
[161] Fix | Delete
if ( isset( $post_type_object ) && $post_type_object->show_in_menu && true !== $post_type_object->show_in_menu ) {
[162] Fix | Delete
$parent_file = $post_type_object->show_in_menu;
[163] Fix | Delete
} else {
[164] Fix | Delete
$parent_file = "edit.php?post_type=$post_type";
[165] Fix | Delete
}
[166] Fix | Delete
$submenu_file = "edit.php?post_type=$post_type";
[167] Fix | Delete
$post_new_file = "post-new.php?post_type=$post_type";
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
$title = $post_type_object->labels->edit_item;
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Allows replacement of the editor.
[174] Fix | Delete
*
[175] Fix | Delete
* @since 4.9.0
[176] Fix | Delete
*
[177] Fix | Delete
* @param bool $replace Whether to replace the editor. Default false.
[178] Fix | Delete
* @param WP_Post $post Post object.
[179] Fix | Delete
*/
[180] Fix | Delete
if ( true === apply_filters( 'replace_editor', false, $post ) ) {
[181] Fix | Delete
break;
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
if ( use_block_editor_for_post( $post ) ) {
[185] Fix | Delete
require ABSPATH . 'wp-admin/edit-form-blocks.php';
[186] Fix | Delete
break;
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
if ( ! wp_check_post_lock( $post->ID ) ) {
[190] Fix | Delete
$active_post_lock = wp_set_post_lock( $post->ID );
[191] Fix | Delete
[192] Fix | Delete
if ( 'attachment' !== $post_type ) {
[193] Fix | Delete
wp_enqueue_script( 'autosave' );
[194] Fix | Delete
}
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
$post = get_post( $post_id, OBJECT, 'edit' );
[198] Fix | Delete
[199] Fix | Delete
if ( post_type_supports( $post_type, 'comments' ) ) {
[200] Fix | Delete
wp_enqueue_script( 'admin-comments' );
[201] Fix | Delete
enqueue_comment_hotkeys_js();
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
require ABSPATH . 'wp-admin/edit-form-advanced.php';
[205] Fix | Delete
[206] Fix | Delete
break;
[207] Fix | Delete
[208] Fix | Delete
case 'editattachment':
[209] Fix | Delete
check_admin_referer( 'update-post_' . $post_id );
[210] Fix | Delete
[211] Fix | Delete
// Don't let these be changed.
[212] Fix | Delete
unset( $_POST['guid'] );
[213] Fix | Delete
$_POST['post_type'] = 'attachment';
[214] Fix | Delete
[215] Fix | Delete
// Update the thumbnail filename.
[216] Fix | Delete
$newmeta = wp_get_attachment_metadata( $post_id, true );
[217] Fix | Delete
$newmeta['thumb'] = wp_basename( $_POST['thumb'] );
[218] Fix | Delete
[219] Fix | Delete
wp_update_attachment_metadata( $post_id, $newmeta );
[220] Fix | Delete
[221] Fix | Delete
// Intentional fall-through to trigger the edit_post() call.
[222] Fix | Delete
case 'editpost':
[223] Fix | Delete
check_admin_referer( 'update-post_' . $post_id );
[224] Fix | Delete
[225] Fix | Delete
$post_id = edit_post();
[226] Fix | Delete
[227] Fix | Delete
// Session cookie flag that the post was saved.
[228] Fix | Delete
if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) {
[229] Fix | Delete
setcookie( 'wp-saving-post', $post_id . '-saved', time() + DAY_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, is_ssl() );
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
redirect_post( $post_id ); // Send user on their way while we keep working.
[233] Fix | Delete
[234] Fix | Delete
exit;
[235] Fix | Delete
[236] Fix | Delete
case 'trash':
[237] Fix | Delete
check_admin_referer( 'trash-post_' . $post_id );
[238] Fix | Delete
[239] Fix | Delete
if ( ! $post ) {
[240] Fix | Delete
wp_die( __( 'The item you are trying to move to the Trash no longer exists.' ) );
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
if ( ! $post_type_object ) {
[244] Fix | Delete
wp_die( __( 'Invalid post type.' ) );
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
if ( ! current_user_can( 'delete_post', $post_id ) ) {
[248] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
[249] Fix | Delete
}
[250] Fix | Delete
[251] Fix | Delete
$user_id = wp_check_post_lock( $post_id );
[252] Fix | Delete
if ( $user_id ) {
[253] Fix | Delete
$user = get_userdata( $user_id );
[254] Fix | Delete
/* translators: %s: User's display name. */
[255] Fix | Delete
wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ) );
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
if ( ! wp_trash_post( $post_id ) ) {
[259] Fix | Delete
wp_die( __( 'Error in moving the item to Trash.' ) );
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
wp_redirect(
[263] Fix | Delete
add_query_arg(
[264] Fix | Delete
array(
[265] Fix | Delete
'trashed' => 1,
[266] Fix | Delete
'ids' => $post_id,
[267] Fix | Delete
),
[268] Fix | Delete
$sendback
[269] Fix | Delete
)
[270] Fix | Delete
);
[271] Fix | Delete
exit;
[272] Fix | Delete
[273] Fix | Delete
case 'untrash':
[274] Fix | Delete
check_admin_referer( 'untrash-post_' . $post_id );
[275] Fix | Delete
[276] Fix | Delete
if ( ! $post ) {
[277] Fix | Delete
wp_die( __( 'The item you are trying to restore from the Trash no longer exists.' ) );
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
if ( ! $post_type_object ) {
[281] Fix | Delete
wp_die( __( 'Invalid post type.' ) );
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
if ( ! current_user_can( 'delete_post', $post_id ) ) {
[285] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) );
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
if ( ! wp_untrash_post( $post_id ) ) {
[289] Fix | Delete
wp_die( __( 'Error in restoring the item from Trash.' ) );
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
$sendback = add_query_arg(
[293] Fix | Delete
array(
[294] Fix | Delete
'untrashed' => 1,
[295] Fix | Delete
'ids' => $post_id,
[296] Fix | Delete
),
[297] Fix | Delete
$sendback
[298] Fix | Delete
);
[299] Fix | Delete
wp_redirect( $sendback );
[300] Fix | Delete
exit;
[301] Fix | Delete
[302] Fix | Delete
case 'delete':
[303] Fix | Delete
check_admin_referer( 'delete-post_' . $post_id );
[304] Fix | Delete
[305] Fix | Delete
if ( ! $post ) {
[306] Fix | Delete
wp_die( __( 'This item has already been deleted.' ) );
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
if ( ! $post_type_object ) {
[310] Fix | Delete
wp_die( __( 'Invalid post type.' ) );
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
if ( ! current_user_can( 'delete_post', $post_id ) ) {
[314] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to delete this item.' ) );
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
if ( 'attachment' === $post->post_type ) {
[318] Fix | Delete
$force = ( ! MEDIA_TRASH );
[319] Fix | Delete
if ( ! wp_delete_attachment( $post_id, $force ) ) {
[320] Fix | Delete
wp_die( __( 'Error in deleting the attachment.' ) );
[321] Fix | Delete
}
[322] Fix | Delete
} else {
[323] Fix | Delete
if ( ! wp_delete_post( $post_id, true ) ) {
[324] Fix | Delete
wp_die( __( 'Error in deleting the item.' ) );
[325] Fix | Delete
}
[326] Fix | Delete
}
[327] Fix | Delete
[328] Fix | Delete
wp_redirect( add_query_arg( 'deleted', 1, $sendback ) );
[329] Fix | Delete
exit;
[330] Fix | Delete
[331] Fix | Delete
case 'preview':
[332] Fix | Delete
check_admin_referer( 'update-post_' . $post_id );
[333] Fix | Delete
[334] Fix | Delete
$url = post_preview();
[335] Fix | Delete
[336] Fix | Delete
wp_redirect( $url );
[337] Fix | Delete
exit;
[338] Fix | Delete
[339] Fix | Delete
case 'toggle-custom-fields':
[340] Fix | Delete
check_admin_referer( 'toggle-custom-fields', 'toggle-custom-fields-nonce' );
[341] Fix | Delete
[342] Fix | Delete
$current_user_id = get_current_user_id();
[343] Fix | Delete
if ( $current_user_id ) {
[344] Fix | Delete
$enable_custom_fields = (bool) get_user_meta( $current_user_id, 'enable_custom_fields', true );
[345] Fix | Delete
update_user_meta( $current_user_id, 'enable_custom_fields', ! $enable_custom_fields );
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
wp_safe_redirect( wp_get_referer() );
[349] Fix | Delete
exit;
[350] Fix | Delete
[351] Fix | Delete
default:
[352] Fix | Delete
/**
[353] Fix | Delete
* Fires for a given custom post action request.
[354] Fix | Delete
*
[355] Fix | Delete
* The dynamic portion of the hook name, `$action`, refers to the custom post action.
[356] Fix | Delete
*
[357] Fix | Delete
* @since 4.6.0
[358] Fix | Delete
*
[359] Fix | Delete
* @param int $post_id Post ID sent with the request.
[360] Fix | Delete
*/
[361] Fix | Delete
do_action( "post_action_{$action}", $post_id );
[362] Fix | Delete
[363] Fix | Delete
wp_redirect( admin_url( 'edit.php' ) );
[364] Fix | Delete
exit;
[365] Fix | Delete
} // End switch.
[366] Fix | Delete
[367] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-footer.php';
[368] Fix | Delete
[369] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function