Edit File by line
/home/zeestwma/ceyloniy.../wp-admin/includes
File: post.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Post Administration API.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Renames `$_POST` data from form names to DB post columns.
[9] Fix | Delete
*
[10] Fix | Delete
* Manipulates `$_POST` directly.
[11] Fix | Delete
*
[12] Fix | Delete
* @since 2.6.0
[13] Fix | Delete
*
[14] Fix | Delete
* @param bool $update Whether the post already exists.
[15] Fix | Delete
* @param array|null $post_data Optional. The array of post data to process.
[16] Fix | Delete
* Defaults to the `$_POST` superglobal.
[17] Fix | Delete
* @return array|WP_Error Array of post data on success, WP_Error on failure.
[18] Fix | Delete
*/
[19] Fix | Delete
function _wp_translate_postdata( $update = false, $post_data = null ) {
[20] Fix | Delete
[21] Fix | Delete
if ( empty( $post_data ) ) {
[22] Fix | Delete
$post_data = &$_POST;
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
if ( $update ) {
[26] Fix | Delete
$post_data['ID'] = (int) $post_data['post_ID'];
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
$ptype = get_post_type_object( $post_data['post_type'] );
[30] Fix | Delete
[31] Fix | Delete
if ( $update && ! current_user_can( 'edit_post', $post_data['ID'] ) ) {
[32] Fix | Delete
if ( 'page' === $post_data['post_type'] ) {
[33] Fix | Delete
return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
[34] Fix | Delete
} else {
[35] Fix | Delete
return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
[36] Fix | Delete
}
[37] Fix | Delete
} elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) {
[38] Fix | Delete
if ( 'page' === $post_data['post_type'] ) {
[39] Fix | Delete
return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
[40] Fix | Delete
} else {
[41] Fix | Delete
return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
[42] Fix | Delete
}
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
if ( isset( $post_data['content'] ) ) {
[46] Fix | Delete
$post_data['post_content'] = $post_data['content'];
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
if ( isset( $post_data['excerpt'] ) ) {
[50] Fix | Delete
$post_data['post_excerpt'] = $post_data['excerpt'];
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
if ( isset( $post_data['parent_id'] ) ) {
[54] Fix | Delete
$post_data['post_parent'] = (int) $post_data['parent_id'];
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
if ( isset( $post_data['trackback_url'] ) ) {
[58] Fix | Delete
$post_data['to_ping'] = $post_data['trackback_url'];
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
$post_data['user_ID'] = get_current_user_id();
[62] Fix | Delete
[63] Fix | Delete
if ( ! empty( $post_data['post_author_override'] ) ) {
[64] Fix | Delete
$post_data['post_author'] = (int) $post_data['post_author_override'];
[65] Fix | Delete
} else {
[66] Fix | Delete
if ( ! empty( $post_data['post_author'] ) ) {
[67] Fix | Delete
$post_data['post_author'] = (int) $post_data['post_author'];
[68] Fix | Delete
} else {
[69] Fix | Delete
$post_data['post_author'] = (int) $post_data['user_ID'];
[70] Fix | Delete
}
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
if ( isset( $post_data['user_ID'] ) && ( $post_data['post_author'] !== $post_data['user_ID'] )
[74] Fix | Delete
&& ! current_user_can( $ptype->cap->edit_others_posts ) ) {
[75] Fix | Delete
[76] Fix | Delete
if ( $update ) {
[77] Fix | Delete
if ( 'page' === $post_data['post_type'] ) {
[78] Fix | Delete
return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
[79] Fix | Delete
} else {
[80] Fix | Delete
return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
[81] Fix | Delete
}
[82] Fix | Delete
} else {
[83] Fix | Delete
if ( 'page' === $post_data['post_type'] ) {
[84] Fix | Delete
return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
[85] Fix | Delete
} else {
[86] Fix | Delete
return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
if ( ! empty( $post_data['post_status'] ) ) {
[92] Fix | Delete
$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
[93] Fix | Delete
[94] Fix | Delete
// No longer an auto-draft.
[95] Fix | Delete
if ( 'auto-draft' === $post_data['post_status'] ) {
[96] Fix | Delete
$post_data['post_status'] = 'draft';
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
if ( ! get_post_status_object( $post_data['post_status'] ) ) {
[100] Fix | Delete
unset( $post_data['post_status'] );
[101] Fix | Delete
}
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
// What to do based on which button they pressed.
[105] Fix | Delete
if ( isset( $post_data['saveasdraft'] ) && '' !== $post_data['saveasdraft'] ) {
[106] Fix | Delete
$post_data['post_status'] = 'draft';
[107] Fix | Delete
}
[108] Fix | Delete
if ( isset( $post_data['saveasprivate'] ) && '' !== $post_data['saveasprivate'] ) {
[109] Fix | Delete
$post_data['post_status'] = 'private';
[110] Fix | Delete
}
[111] Fix | Delete
if ( isset( $post_data['publish'] ) && ( '' !== $post_data['publish'] )
[112] Fix | Delete
&& ( ! isset( $post_data['post_status'] ) || 'private' !== $post_data['post_status'] )
[113] Fix | Delete
) {
[114] Fix | Delete
$post_data['post_status'] = 'publish';
[115] Fix | Delete
}
[116] Fix | Delete
if ( isset( $post_data['advanced'] ) && '' !== $post_data['advanced'] ) {
[117] Fix | Delete
$post_data['post_status'] = 'draft';
[118] Fix | Delete
}
[119] Fix | Delete
if ( isset( $post_data['pending'] ) && '' !== $post_data['pending'] ) {
[120] Fix | Delete
$post_data['post_status'] = 'pending';
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
if ( isset( $post_data['ID'] ) ) {
[124] Fix | Delete
$post_id = $post_data['ID'];
[125] Fix | Delete
} else {
[126] Fix | Delete
$post_id = false;
[127] Fix | Delete
}
[128] Fix | Delete
$previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;
[129] Fix | Delete
[130] Fix | Delete
if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) {
[131] Fix | Delete
$post_data['post_status'] = $previous_status ? $previous_status : 'pending';
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
$published_statuses = array( 'publish', 'future' );
[135] Fix | Delete
[136] Fix | Delete
/*
[137] Fix | Delete
* Posts 'submitted for approval' are submitted to $_POST the same as if they were being published.
[138] Fix | Delete
* Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
[139] Fix | Delete
*/
[140] Fix | Delete
if ( isset( $post_data['post_status'] )
[141] Fix | Delete
&& ( in_array( $post_data['post_status'], $published_statuses, true )
[142] Fix | Delete
&& ! current_user_can( $ptype->cap->publish_posts ) )
[143] Fix | Delete
) {
[144] Fix | Delete
if ( ! in_array( $previous_status, $published_statuses, true ) || ! current_user_can( 'edit_post', $post_id ) ) {
[145] Fix | Delete
$post_data['post_status'] = 'pending';
[146] Fix | Delete
}
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
if ( ! isset( $post_data['post_status'] ) ) {
[150] Fix | Delete
$post_data['post_status'] = 'auto-draft' === $previous_status ? 'draft' : $previous_status;
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
if ( isset( $post_data['post_password'] ) && ! current_user_can( $ptype->cap->publish_posts ) ) {
[154] Fix | Delete
unset( $post_data['post_password'] );
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
if ( ! isset( $post_data['comment_status'] ) ) {
[158] Fix | Delete
$post_data['comment_status'] = 'closed';
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
if ( ! isset( $post_data['ping_status'] ) ) {
[162] Fix | Delete
$post_data['ping_status'] = 'closed';
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) {
[166] Fix | Delete
if ( ! empty( $post_data[ 'hidden_' . $timeunit ] ) && $post_data[ 'hidden_' . $timeunit ] !== $post_data[ $timeunit ] ) {
[167] Fix | Delete
$post_data['edit_date'] = '1';
[168] Fix | Delete
break;
[169] Fix | Delete
}
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
if ( ! empty( $post_data['edit_date'] ) ) {
[173] Fix | Delete
$aa = $post_data['aa'];
[174] Fix | Delete
$mm = $post_data['mm'];
[175] Fix | Delete
$jj = $post_data['jj'];
[176] Fix | Delete
$hh = $post_data['hh'];
[177] Fix | Delete
$mn = $post_data['mn'];
[178] Fix | Delete
$ss = $post_data['ss'];
[179] Fix | Delete
$aa = ( $aa <= 0 ) ? gmdate( 'Y' ) : $aa;
[180] Fix | Delete
$mm = ( $mm <= 0 ) ? gmdate( 'n' ) : $mm;
[181] Fix | Delete
$jj = ( $jj > 31 ) ? 31 : $jj;
[182] Fix | Delete
$jj = ( $jj <= 0 ) ? gmdate( 'j' ) : $jj;
[183] Fix | Delete
$hh = ( $hh > 23 ) ? $hh - 24 : $hh;
[184] Fix | Delete
$mn = ( $mn > 59 ) ? $mn - 60 : $mn;
[185] Fix | Delete
$ss = ( $ss > 59 ) ? $ss - 60 : $ss;
[186] Fix | Delete
[187] Fix | Delete
$post_data['post_date'] = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $aa, $mm, $jj, $hh, $mn, $ss );
[188] Fix | Delete
[189] Fix | Delete
$valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] );
[190] Fix | Delete
if ( ! $valid_date ) {
[191] Fix | Delete
return new WP_Error( 'invalid_date', __( 'Invalid date.' ) );
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
/*
[195] Fix | Delete
* Only assign a post date if the user has explicitly set a new value.
[196] Fix | Delete
* See #59125 and #19907.
[197] Fix | Delete
*/
[198] Fix | Delete
$previous_date = $post_id ? get_post_field( 'post_date', $post_id ) : false;
[199] Fix | Delete
if ( $previous_date && $previous_date !== $post_data['post_date'] ) {
[200] Fix | Delete
$post_data['edit_date'] = true;
[201] Fix | Delete
$post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
[202] Fix | Delete
} else {
[203] Fix | Delete
$post_data['edit_date'] = false;
[204] Fix | Delete
unset( $post_data['post_date'] );
[205] Fix | Delete
unset( $post_data['post_date_gmt'] );
[206] Fix | Delete
}
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
if ( isset( $post_data['post_category'] ) ) {
[210] Fix | Delete
$category_object = get_taxonomy( 'category' );
[211] Fix | Delete
if ( ! current_user_can( $category_object->cap->assign_terms ) ) {
[212] Fix | Delete
unset( $post_data['post_category'] );
[213] Fix | Delete
}
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
return $post_data;
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* Returns only allowed post data fields.
[221] Fix | Delete
*
[222] Fix | Delete
* @since 5.0.1
[223] Fix | Delete
*
[224] Fix | Delete
* @param array|WP_Error|null $post_data The array of post data to process, or an error object.
[225] Fix | Delete
* Defaults to the `$_POST` superglobal.
[226] Fix | Delete
* @return array|WP_Error Array of post data on success, WP_Error on failure.
[227] Fix | Delete
*/
[228] Fix | Delete
function _wp_get_allowed_postdata( $post_data = null ) {
[229] Fix | Delete
if ( empty( $post_data ) ) {
[230] Fix | Delete
$post_data = $_POST;
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
// Pass through errors.
[234] Fix | Delete
if ( is_wp_error( $post_data ) ) {
[235] Fix | Delete
return $post_data;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) );
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
/**
[242] Fix | Delete
* Updates an existing post with values provided in `$_POST`.
[243] Fix | Delete
*
[244] Fix | Delete
* If post data is passed as an argument, it is treated as an array of data
[245] Fix | Delete
* keyed appropriately for turning into a post object.
[246] Fix | Delete
*
[247] Fix | Delete
* If post data is not passed, the `$_POST` global variable is used instead.
[248] Fix | Delete
*
[249] Fix | Delete
* @since 1.5.0
[250] Fix | Delete
*
[251] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[252] Fix | Delete
*
[253] Fix | Delete
* @param array|null $post_data Optional. The array of post data to process.
[254] Fix | Delete
* Defaults to the `$_POST` superglobal.
[255] Fix | Delete
* @return int Post ID.
[256] Fix | Delete
*/
[257] Fix | Delete
function edit_post( $post_data = null ) {
[258] Fix | Delete
global $wpdb;
[259] Fix | Delete
[260] Fix | Delete
if ( empty( $post_data ) ) {
[261] Fix | Delete
$post_data = &$_POST;
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
// Clear out any data in internal vars.
[265] Fix | Delete
unset( $post_data['filter'] );
[266] Fix | Delete
[267] Fix | Delete
$post_id = (int) $post_data['post_ID'];
[268] Fix | Delete
$post = get_post( $post_id );
[269] Fix | Delete
[270] Fix | Delete
$post_data['post_type'] = $post->post_type;
[271] Fix | Delete
$post_data['post_mime_type'] = $post->post_mime_type;
[272] Fix | Delete
[273] Fix | Delete
if ( ! empty( $post_data['post_status'] ) ) {
[274] Fix | Delete
$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
[275] Fix | Delete
[276] Fix | Delete
if ( 'inherit' === $post_data['post_status'] ) {
[277] Fix | Delete
unset( $post_data['post_status'] );
[278] Fix | Delete
}
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
$ptype = get_post_type_object( $post_data['post_type'] );
[282] Fix | Delete
if ( ! current_user_can( 'edit_post', $post_id ) ) {
[283] Fix | Delete
if ( 'page' === $post_data['post_type'] ) {
[284] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
[285] Fix | Delete
} else {
[286] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
[287] Fix | Delete
}
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
if ( post_type_supports( $ptype->name, 'revisions' ) ) {
[291] Fix | Delete
$revisions = wp_get_post_revisions(
[292] Fix | Delete
$post_id,
[293] Fix | Delete
array(
[294] Fix | Delete
'order' => 'ASC',
[295] Fix | Delete
'posts_per_page' => 1,
[296] Fix | Delete
)
[297] Fix | Delete
);
[298] Fix | Delete
$revision = current( $revisions );
[299] Fix | Delete
[300] Fix | Delete
// Check if the revisions have been upgraded.
[301] Fix | Delete
if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) {
[302] Fix | Delete
_wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_id ) );
[303] Fix | Delete
}
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
if ( isset( $post_data['visibility'] ) ) {
[307] Fix | Delete
switch ( $post_data['visibility'] ) {
[308] Fix | Delete
case 'public':
[309] Fix | Delete
$post_data['post_password'] = '';
[310] Fix | Delete
break;
[311] Fix | Delete
case 'password':
[312] Fix | Delete
unset( $post_data['sticky'] );
[313] Fix | Delete
break;
[314] Fix | Delete
case 'private':
[315] Fix | Delete
$post_data['post_status'] = 'private';
[316] Fix | Delete
$post_data['post_password'] = '';
[317] Fix | Delete
unset( $post_data['sticky'] );
[318] Fix | Delete
break;
[319] Fix | Delete
}
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
$post_data = _wp_translate_postdata( true, $post_data );
[323] Fix | Delete
if ( is_wp_error( $post_data ) ) {
[324] Fix | Delete
wp_die( $post_data->get_error_message() );
[325] Fix | Delete
}
[326] Fix | Delete
$translated = _wp_get_allowed_postdata( $post_data );
[327] Fix | Delete
[328] Fix | Delete
// Post formats.
[329] Fix | Delete
if ( isset( $post_data['post_format'] ) ) {
[330] Fix | Delete
set_post_format( $post_id, $post_data['post_format'] );
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
$format_meta_urls = array( 'url', 'link_url', 'quote_source_url' );
[334] Fix | Delete
foreach ( $format_meta_urls as $format_meta_url ) {
[335] Fix | Delete
$keyed = '_format_' . $format_meta_url;
[336] Fix | Delete
if ( isset( $post_data[ $keyed ] ) ) {
[337] Fix | Delete
update_post_meta( $post_id, $keyed, wp_slash( sanitize_url( wp_unslash( $post_data[ $keyed ] ) ) ) );
[338] Fix | Delete
}
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
$format_keys = array( 'quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed' );
[342] Fix | Delete
[343] Fix | Delete
foreach ( $format_keys as $key ) {
[344] Fix | Delete
$keyed = '_format_' . $key;
[345] Fix | Delete
if ( isset( $post_data[ $keyed ] ) ) {
[346] Fix | Delete
if ( current_user_can( 'unfiltered_html' ) ) {
[347] Fix | Delete
update_post_meta( $post_id, $keyed, $post_data[ $keyed ] );
[348] Fix | Delete
} else {
[349] Fix | Delete
update_post_meta( $post_id, $keyed, wp_filter_post_kses( $post_data[ $keyed ] ) );
[350] Fix | Delete
}
[351] Fix | Delete
}
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
if ( 'attachment' === $post_data['post_type'] && preg_match( '#^(audio|video)/#', $post_data['post_mime_type'] ) ) {
[355] Fix | Delete
$id3data = wp_get_attachment_metadata( $post_id );
[356] Fix | Delete
if ( ! is_array( $id3data ) ) {
[357] Fix | Delete
$id3data = array();
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) {
[361] Fix | Delete
if ( isset( $post_data[ 'id3_' . $key ] ) ) {
[362] Fix | Delete
$id3data[ $key ] = sanitize_text_field( wp_unslash( $post_data[ 'id3_' . $key ] ) );
[363] Fix | Delete
}
[364] Fix | Delete
}
[365] Fix | Delete
wp_update_attachment_metadata( $post_id, $id3data );
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
// Meta stuff.
[369] Fix | Delete
if ( isset( $post_data['meta'] ) && $post_data['meta'] ) {
[370] Fix | Delete
foreach ( $post_data['meta'] as $key => $value ) {
[371] Fix | Delete
$meta = get_post_meta_by_id( $key );
[372] Fix | Delete
if ( ! $meta ) {
[373] Fix | Delete
continue;
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
if ( (int) $meta->post_id !== $post_id ) {
[377] Fix | Delete
continue;
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
if ( is_protected_meta( $meta->meta_key, 'post' )
[381] Fix | Delete
|| ! current_user_can( 'edit_post_meta', $post_id, $meta->meta_key )
[382] Fix | Delete
) {
[383] Fix | Delete
continue;
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
if ( is_protected_meta( $value['key'], 'post' )
[387] Fix | Delete
|| ! current_user_can( 'edit_post_meta', $post_id, $value['key'] )
[388] Fix | Delete
) {
[389] Fix | Delete
continue;
[390] Fix | Delete
}
[391] Fix | Delete
[392] Fix | Delete
update_meta( $key, $value['key'], $value['value'] );
[393] Fix | Delete
}
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
if ( isset( $post_data['deletemeta'] ) && $post_data['deletemeta'] ) {
[397] Fix | Delete
foreach ( $post_data['deletemeta'] as $key => $value ) {
[398] Fix | Delete
$meta = get_post_meta_by_id( $key );
[399] Fix | Delete
if ( ! $meta ) {
[400] Fix | Delete
continue;
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
if ( (int) $meta->post_id !== $post_id ) {
[404] Fix | Delete
continue;
[405] Fix | Delete
}
[406] Fix | Delete
[407] Fix | Delete
if ( is_protected_meta( $meta->meta_key, 'post' )
[408] Fix | Delete
|| ! current_user_can( 'delete_post_meta', $post_id, $meta->meta_key )
[409] Fix | Delete
) {
[410] Fix | Delete
continue;
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
delete_meta( $key );
[414] Fix | Delete
}
[415] Fix | Delete
}
[416] Fix | Delete
[417] Fix | Delete
// Attachment stuff.
[418] Fix | Delete
if ( 'attachment' === $post_data['post_type'] ) {
[419] Fix | Delete
if ( isset( $post_data['_wp_attachment_image_alt'] ) ) {
[420] Fix | Delete
$image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] );
[421] Fix | Delete
[422] Fix | Delete
if ( get_post_meta( $post_id, '_wp_attachment_image_alt', true ) !== $image_alt ) {
[423] Fix | Delete
$image_alt = wp_strip_all_tags( $image_alt, true );
[424] Fix | Delete
[425] Fix | Delete
// update_post_meta() expects slashed.
[426] Fix | Delete
update_post_meta( $post_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
[427] Fix | Delete
}
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
$attachment_data = isset( $post_data['attachments'][ $post_id ] ) ? $post_data['attachments'][ $post_id ] : array();
[431] Fix | Delete
[432] Fix | Delete
/** This filter is documented in wp-admin/includes/media.php */
[433] Fix | Delete
$translated = apply_filters( 'attachment_fields_to_save', $translated, $attachment_data );
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
// Convert taxonomy input to term IDs, to avoid ambiguity.
[437] Fix | Delete
if ( isset( $post_data['tax_input'] ) ) {
[438] Fix | Delete
foreach ( (array) $post_data['tax_input'] as $taxonomy => $terms ) {
[439] Fix | Delete
$tax_object = get_taxonomy( $taxonomy );
[440] Fix | Delete
[441] Fix | Delete
if ( $tax_object && isset( $tax_object->meta_box_sanitize_cb ) ) {
[442] Fix | Delete
$translated['tax_input'][ $taxonomy ] = call_user_func_array( $tax_object->meta_box_sanitize_cb, array( $taxonomy, $terms ) );
[443] Fix | Delete
}
[444] Fix | Delete
}
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
add_meta( $post_id );
[448] Fix | Delete
[449] Fix | Delete
update_post_meta( $post_id, '_edit_last', get_current_user_id() );
[450] Fix | Delete
[451] Fix | Delete
$success = wp_update_post( $translated );
[452] Fix | Delete
[453] Fix | Delete
// If the save failed, see if we can confidence check the main fields and try again.
[454] Fix | Delete
if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
[455] Fix | Delete
$fields = array( 'post_title', 'post_content', 'post_excerpt' );
[456] Fix | Delete
[457] Fix | Delete
foreach ( $fields as $field ) {
[458] Fix | Delete
if ( isset( $translated[ $field ] ) ) {
[459] Fix | Delete
$translated[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $translated[ $field ] );
[460] Fix | Delete
}
[461] Fix | Delete
}
[462] Fix | Delete
[463] Fix | Delete
wp_update_post( $translated );
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
// Now that we have an ID we can fix any attachment anchor hrefs.
[467] Fix | Delete
_fix_attachment_links( $post_id );
[468] Fix | Delete
[469] Fix | Delete
wp_set_post_lock( $post_id );
[470] Fix | Delete
[471] Fix | Delete
if ( current_user_can( $ptype->cap->edit_others_posts ) && current_user_can( $ptype->cap->publish_posts ) ) {
[472] Fix | Delete
if ( ! empty( $post_data['sticky'] ) ) {
[473] Fix | Delete
stick_post( $post_id );
[474] Fix | Delete
} else {
[475] Fix | Delete
unstick_post( $post_id );
[476] Fix | Delete
}
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
return $post_id;
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
/**
[483] Fix | Delete
* Processes the post data for the bulk editing of posts.
[484] Fix | Delete
*
[485] Fix | Delete
* Updates all bulk edited posts/pages, adding (but not removing) tags and
[486] Fix | Delete
* categories. Skips pages when they would be their own parent or child.
[487] Fix | Delete
*
[488] Fix | Delete
* @since 2.7.0
[489] Fix | Delete
*
[490] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[491] Fix | Delete
*
[492] Fix | Delete
* @param array|null $post_data Optional. The array of post data to process.
[493] Fix | Delete
* Defaults to the `$_POST` superglobal.
[494] Fix | Delete
* @return array {
[495] Fix | Delete
* An array of updated, skipped, and locked post IDs.
[496] Fix | Delete
*
[497] Fix | Delete
* @type int[] $updated An array of updated post IDs.
[498] Fix | Delete
* @type int[] $skipped An array of skipped post IDs.
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function