Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu...
File: post.php
* Filters whether or not to add a `__trashed` suffix to trashed posts that match the name of the updated post.
[4500] Fix | Delete
*
[4501] Fix | Delete
* @since 5.4.0
[4502] Fix | Delete
*
[4503] Fix | Delete
* @param bool $add_trashed_suffix Whether to attempt to add the suffix.
[4504] Fix | Delete
* @param string $post_name The name of the post being updated.
[4505] Fix | Delete
* @param int $post_id Post ID.
[4506] Fix | Delete
*/
[4507] Fix | Delete
$add_trashed_suffix = apply_filters( 'add_trashed_suffix_to_trashed_posts', true, $post_name, $post_id );
[4508] Fix | Delete
[4509] Fix | Delete
if ( $add_trashed_suffix ) {
[4510] Fix | Delete
wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_id );
[4511] Fix | Delete
}
[4512] Fix | Delete
}
[4513] Fix | Delete
[4514] Fix | Delete
// When trashing an existing post, change its slug to allow non-trashed posts to use it.
[4515] Fix | Delete
if ( 'trash' === $post_status && 'trash' !== $previous_status && 'new' !== $previous_status ) {
[4516] Fix | Delete
$post_name = wp_add_trashed_suffix_to_post_name_for_post( $post_id );
[4517] Fix | Delete
}
[4518] Fix | Delete
[4519] Fix | Delete
$post_name = wp_unique_post_slug( $post_name, $post_id, $post_status, $post_type, $post_parent );
[4520] Fix | Delete
[4521] Fix | Delete
// Don't unslash.
[4522] Fix | Delete
$post_mime_type = isset( $postarr['post_mime_type'] ) ? $postarr['post_mime_type'] : '';
[4523] Fix | Delete
[4524] Fix | Delete
// Expected_slashed (everything!).
[4525] Fix | Delete
$data = compact(
[4526] Fix | Delete
'post_author',
[4527] Fix | Delete
'post_date',
[4528] Fix | Delete
'post_date_gmt',
[4529] Fix | Delete
'post_content',
[4530] Fix | Delete
'post_content_filtered',
[4531] Fix | Delete
'post_title',
[4532] Fix | Delete
'post_excerpt',
[4533] Fix | Delete
'post_status',
[4534] Fix | Delete
'post_type',
[4535] Fix | Delete
'comment_status',
[4536] Fix | Delete
'ping_status',
[4537] Fix | Delete
'post_password',
[4538] Fix | Delete
'post_name',
[4539] Fix | Delete
'to_ping',
[4540] Fix | Delete
'pinged',
[4541] Fix | Delete
'post_modified',
[4542] Fix | Delete
'post_modified_gmt',
[4543] Fix | Delete
'post_parent',
[4544] Fix | Delete
'menu_order',
[4545] Fix | Delete
'post_mime_type',
[4546] Fix | Delete
'guid'
[4547] Fix | Delete
);
[4548] Fix | Delete
[4549] Fix | Delete
$emoji_fields = array( 'post_title', 'post_content', 'post_excerpt' );
[4550] Fix | Delete
[4551] Fix | Delete
foreach ( $emoji_fields as $emoji_field ) {
[4552] Fix | Delete
if ( isset( $data[ $emoji_field ] ) ) {
[4553] Fix | Delete
$charset = $wpdb->get_col_charset( $wpdb->posts, $emoji_field );
[4554] Fix | Delete
[4555] Fix | Delete
if ( 'utf8' === $charset ) {
[4556] Fix | Delete
$data[ $emoji_field ] = wp_encode_emoji( $data[ $emoji_field ] );
[4557] Fix | Delete
}
[4558] Fix | Delete
}
[4559] Fix | Delete
}
[4560] Fix | Delete
[4561] Fix | Delete
if ( 'attachment' === $post_type ) {
[4562] Fix | Delete
/**
[4563] Fix | Delete
* Filters attachment post data before it is updated in or added to the database.
[4564] Fix | Delete
*
[4565] Fix | Delete
* @since 3.9.0
[4566] Fix | Delete
* @since 5.4.1 The `$unsanitized_postarr` parameter was added.
[4567] Fix | Delete
* @since 6.0.0 The `$update` parameter was added.
[4568] Fix | Delete
*
[4569] Fix | Delete
* @param array $data An array of slashed, sanitized, and processed attachment post data.
[4570] Fix | Delete
* @param array $postarr An array of slashed and sanitized attachment post data, but not processed.
[4571] Fix | Delete
* @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed attachment post data
[4572] Fix | Delete
* as originally passed to wp_insert_post().
[4573] Fix | Delete
* @param bool $update Whether this is an existing attachment post being updated.
[4574] Fix | Delete
*/
[4575] Fix | Delete
$data = apply_filters( 'wp_insert_attachment_data', $data, $postarr, $unsanitized_postarr, $update );
[4576] Fix | Delete
} else {
[4577] Fix | Delete
/**
[4578] Fix | Delete
* Filters slashed post data just before it is inserted into the database.
[4579] Fix | Delete
*
[4580] Fix | Delete
* @since 2.7.0
[4581] Fix | Delete
* @since 5.4.1 The `$unsanitized_postarr` parameter was added.
[4582] Fix | Delete
* @since 6.0.0 The `$update` parameter was added.
[4583] Fix | Delete
*
[4584] Fix | Delete
* @param array $data An array of slashed, sanitized, and processed post data.
[4585] Fix | Delete
* @param array $postarr An array of sanitized (and slashed) but otherwise unmodified post data.
[4586] Fix | Delete
* @param array $unsanitized_postarr An array of slashed yet *unsanitized* and unprocessed post data as
[4587] Fix | Delete
* originally passed to wp_insert_post().
[4588] Fix | Delete
* @param bool $update Whether this is an existing post being updated.
[4589] Fix | Delete
*/
[4590] Fix | Delete
$data = apply_filters( 'wp_insert_post_data', $data, $postarr, $unsanitized_postarr, $update );
[4591] Fix | Delete
}
[4592] Fix | Delete
[4593] Fix | Delete
$data = wp_unslash( $data );
[4594] Fix | Delete
$where = array( 'ID' => $post_id );
[4595] Fix | Delete
[4596] Fix | Delete
if ( $update ) {
[4597] Fix | Delete
/**
[4598] Fix | Delete
* Fires immediately before an existing post is updated in the database.
[4599] Fix | Delete
*
[4600] Fix | Delete
* @since 2.5.0
[4601] Fix | Delete
*
[4602] Fix | Delete
* @param int $post_id Post ID.
[4603] Fix | Delete
* @param array $data Array of unslashed post data.
[4604] Fix | Delete
*/
[4605] Fix | Delete
do_action( 'pre_post_update', $post_id, $data );
[4606] Fix | Delete
[4607] Fix | Delete
if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) {
[4608] Fix | Delete
if ( $wp_error ) {
[4609] Fix | Delete
if ( 'attachment' === $post_type ) {
[4610] Fix | Delete
$message = __( 'Could not update attachment in the database.' );
[4611] Fix | Delete
} else {
[4612] Fix | Delete
$message = __( 'Could not update post in the database.' );
[4613] Fix | Delete
}
[4614] Fix | Delete
[4615] Fix | Delete
return new WP_Error( 'db_update_error', $message, $wpdb->last_error );
[4616] Fix | Delete
} else {
[4617] Fix | Delete
return 0;
[4618] Fix | Delete
}
[4619] Fix | Delete
}
[4620] Fix | Delete
} else {
[4621] Fix | Delete
// If there is a suggested ID, use it if not already present.
[4622] Fix | Delete
if ( ! empty( $import_id ) ) {
[4623] Fix | Delete
$import_id = (int) $import_id;
[4624] Fix | Delete
[4625] Fix | Delete
if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id ) ) ) {
[4626] Fix | Delete
$data['ID'] = $import_id;
[4627] Fix | Delete
}
[4628] Fix | Delete
}
[4629] Fix | Delete
[4630] Fix | Delete
if ( false === $wpdb->insert( $wpdb->posts, $data ) ) {
[4631] Fix | Delete
if ( $wp_error ) {
[4632] Fix | Delete
if ( 'attachment' === $post_type ) {
[4633] Fix | Delete
$message = __( 'Could not insert attachment into the database.' );
[4634] Fix | Delete
} else {
[4635] Fix | Delete
$message = __( 'Could not insert post into the database.' );
[4636] Fix | Delete
}
[4637] Fix | Delete
[4638] Fix | Delete
return new WP_Error( 'db_insert_error', $message, $wpdb->last_error );
[4639] Fix | Delete
} else {
[4640] Fix | Delete
return 0;
[4641] Fix | Delete
}
[4642] Fix | Delete
}
[4643] Fix | Delete
[4644] Fix | Delete
$post_id = (int) $wpdb->insert_id;
[4645] Fix | Delete
[4646] Fix | Delete
// Use the newly generated $post_id.
[4647] Fix | Delete
$where = array( 'ID' => $post_id );
[4648] Fix | Delete
}
[4649] Fix | Delete
[4650] Fix | Delete
if ( empty( $data['post_name'] ) && ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ), true ) ) {
[4651] Fix | Delete
$data['post_name'] = wp_unique_post_slug( sanitize_title( $data['post_title'], $post_id ), $post_id, $data['post_status'], $post_type, $post_parent );
[4652] Fix | Delete
[4653] Fix | Delete
$wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where );
[4654] Fix | Delete
clean_post_cache( $post_id );
[4655] Fix | Delete
}
[4656] Fix | Delete
[4657] Fix | Delete
if ( is_object_in_taxonomy( $post_type, 'category' ) ) {
[4658] Fix | Delete
wp_set_post_categories( $post_id, $post_category );
[4659] Fix | Delete
}
[4660] Fix | Delete
[4661] Fix | Delete
if ( isset( $postarr['tags_input'] ) && is_object_in_taxonomy( $post_type, 'post_tag' ) ) {
[4662] Fix | Delete
wp_set_post_tags( $post_id, $postarr['tags_input'] );
[4663] Fix | Delete
}
[4664] Fix | Delete
[4665] Fix | Delete
// Add default term for all associated custom taxonomies.
[4666] Fix | Delete
if ( 'auto-draft' !== $post_status ) {
[4667] Fix | Delete
foreach ( get_object_taxonomies( $post_type, 'object' ) as $taxonomy => $tax_object ) {
[4668] Fix | Delete
[4669] Fix | Delete
if ( ! empty( $tax_object->default_term ) ) {
[4670] Fix | Delete
[4671] Fix | Delete
// Filter out empty terms.
[4672] Fix | Delete
if ( isset( $postarr['tax_input'][ $taxonomy ] ) && is_array( $postarr['tax_input'][ $taxonomy ] ) ) {
[4673] Fix | Delete
$postarr['tax_input'][ $taxonomy ] = array_filter( $postarr['tax_input'][ $taxonomy ] );
[4674] Fix | Delete
}
[4675] Fix | Delete
[4676] Fix | Delete
// Passed custom taxonomy list overwrites the existing list if not empty.
[4677] Fix | Delete
$terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'ids' ) );
[4678] Fix | Delete
if ( ! empty( $terms ) && empty( $postarr['tax_input'][ $taxonomy ] ) ) {
[4679] Fix | Delete
$postarr['tax_input'][ $taxonomy ] = $terms;
[4680] Fix | Delete
}
[4681] Fix | Delete
[4682] Fix | Delete
if ( empty( $postarr['tax_input'][ $taxonomy ] ) ) {
[4683] Fix | Delete
$default_term_id = get_option( 'default_term_' . $taxonomy );
[4684] Fix | Delete
if ( ! empty( $default_term_id ) ) {
[4685] Fix | Delete
$postarr['tax_input'][ $taxonomy ] = array( (int) $default_term_id );
[4686] Fix | Delete
}
[4687] Fix | Delete
}
[4688] Fix | Delete
}
[4689] Fix | Delete
}
[4690] Fix | Delete
}
[4691] Fix | Delete
[4692] Fix | Delete
// New-style support for all custom taxonomies.
[4693] Fix | Delete
if ( ! empty( $postarr['tax_input'] ) ) {
[4694] Fix | Delete
foreach ( $postarr['tax_input'] as $taxonomy => $tags ) {
[4695] Fix | Delete
$taxonomy_obj = get_taxonomy( $taxonomy );
[4696] Fix | Delete
[4697] Fix | Delete
if ( ! $taxonomy_obj ) {
[4698] Fix | Delete
/* translators: %s: Taxonomy name. */
[4699] Fix | Delete
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid taxonomy: %s.' ), $taxonomy ), '4.4.0' );
[4700] Fix | Delete
continue;
[4701] Fix | Delete
}
[4702] Fix | Delete
[4703] Fix | Delete
// array = hierarchical, string = non-hierarchical.
[4704] Fix | Delete
if ( is_array( $tags ) ) {
[4705] Fix | Delete
$tags = array_filter( $tags );
[4706] Fix | Delete
}
[4707] Fix | Delete
[4708] Fix | Delete
if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
[4709] Fix | Delete
wp_set_post_terms( $post_id, $tags, $taxonomy );
[4710] Fix | Delete
}
[4711] Fix | Delete
}
[4712] Fix | Delete
}
[4713] Fix | Delete
[4714] Fix | Delete
if ( ! empty( $postarr['meta_input'] ) ) {
[4715] Fix | Delete
foreach ( $postarr['meta_input'] as $field => $value ) {
[4716] Fix | Delete
update_post_meta( $post_id, $field, $value );
[4717] Fix | Delete
}
[4718] Fix | Delete
}
[4719] Fix | Delete
[4720] Fix | Delete
$current_guid = get_post_field( 'guid', $post_id );
[4721] Fix | Delete
[4722] Fix | Delete
// Set GUID.
[4723] Fix | Delete
if ( ! $update && '' === $current_guid ) {
[4724] Fix | Delete
$wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_id ) ), $where );
[4725] Fix | Delete
}
[4726] Fix | Delete
[4727] Fix | Delete
if ( 'attachment' === $postarr['post_type'] ) {
[4728] Fix | Delete
if ( ! empty( $postarr['file'] ) ) {
[4729] Fix | Delete
update_attached_file( $post_id, $postarr['file'] );
[4730] Fix | Delete
}
[4731] Fix | Delete
[4732] Fix | Delete
if ( ! empty( $postarr['context'] ) ) {
[4733] Fix | Delete
add_post_meta( $post_id, '_wp_attachment_context', $postarr['context'], true );
[4734] Fix | Delete
}
[4735] Fix | Delete
}
[4736] Fix | Delete
[4737] Fix | Delete
// Set or remove featured image.
[4738] Fix | Delete
if ( isset( $postarr['_thumbnail_id'] ) ) {
[4739] Fix | Delete
$thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type;
[4740] Fix | Delete
[4741] Fix | Delete
if ( ! $thumbnail_support && 'attachment' === $post_type && $post_mime_type ) {
[4742] Fix | Delete
if ( wp_attachment_is( 'audio', $post_id ) ) {
[4743] Fix | Delete
$thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
[4744] Fix | Delete
} elseif ( wp_attachment_is( 'video', $post_id ) ) {
[4745] Fix | Delete
$thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
[4746] Fix | Delete
}
[4747] Fix | Delete
}
[4748] Fix | Delete
[4749] Fix | Delete
if ( $thumbnail_support ) {
[4750] Fix | Delete
$thumbnail_id = (int) $postarr['_thumbnail_id'];
[4751] Fix | Delete
if ( -1 === $thumbnail_id ) {
[4752] Fix | Delete
delete_post_thumbnail( $post_id );
[4753] Fix | Delete
} else {
[4754] Fix | Delete
set_post_thumbnail( $post_id, $thumbnail_id );
[4755] Fix | Delete
}
[4756] Fix | Delete
}
[4757] Fix | Delete
}
[4758] Fix | Delete
[4759] Fix | Delete
clean_post_cache( $post_id );
[4760] Fix | Delete
[4761] Fix | Delete
$post = get_post( $post_id );
[4762] Fix | Delete
[4763] Fix | Delete
if ( ! empty( $postarr['page_template'] ) ) {
[4764] Fix | Delete
$post->page_template = $postarr['page_template'];
[4765] Fix | Delete
$page_templates = wp_get_theme()->get_page_templates( $post );
[4766] Fix | Delete
[4767] Fix | Delete
if ( 'default' !== $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
[4768] Fix | Delete
if ( $wp_error ) {
[4769] Fix | Delete
return new WP_Error( 'invalid_page_template', __( 'Invalid page template.' ) );
[4770] Fix | Delete
}
[4771] Fix | Delete
[4772] Fix | Delete
update_post_meta( $post_id, '_wp_page_template', 'default' );
[4773] Fix | Delete
} else {
[4774] Fix | Delete
update_post_meta( $post_id, '_wp_page_template', $postarr['page_template'] );
[4775] Fix | Delete
}
[4776] Fix | Delete
}
[4777] Fix | Delete
[4778] Fix | Delete
if ( 'attachment' !== $postarr['post_type'] ) {
[4779] Fix | Delete
wp_transition_post_status( $data['post_status'], $previous_status, $post );
[4780] Fix | Delete
} else {
[4781] Fix | Delete
if ( $update ) {
[4782] Fix | Delete
/**
[4783] Fix | Delete
* Fires once an existing attachment has been updated.
[4784] Fix | Delete
*
[4785] Fix | Delete
* @since 2.0.0
[4786] Fix | Delete
*
[4787] Fix | Delete
* @param int $post_id Attachment ID.
[4788] Fix | Delete
*/
[4789] Fix | Delete
do_action( 'edit_attachment', $post_id );
[4790] Fix | Delete
[4791] Fix | Delete
$post_after = get_post( $post_id );
[4792] Fix | Delete
[4793] Fix | Delete
/**
[4794] Fix | Delete
* Fires once an existing attachment has been updated.
[4795] Fix | Delete
*
[4796] Fix | Delete
* @since 4.4.0
[4797] Fix | Delete
*
[4798] Fix | Delete
* @param int $post_id Post ID.
[4799] Fix | Delete
* @param WP_Post $post_after Post object following the update.
[4800] Fix | Delete
* @param WP_Post $post_before Post object before the update.
[4801] Fix | Delete
*/
[4802] Fix | Delete
do_action( 'attachment_updated', $post_id, $post_after, $post_before );
[4803] Fix | Delete
} else {
[4804] Fix | Delete
[4805] Fix | Delete
/**
[4806] Fix | Delete
* Fires once an attachment has been added.
[4807] Fix | Delete
*
[4808] Fix | Delete
* @since 2.0.0
[4809] Fix | Delete
*
[4810] Fix | Delete
* @param int $post_id Attachment ID.
[4811] Fix | Delete
*/
[4812] Fix | Delete
do_action( 'add_attachment', $post_id );
[4813] Fix | Delete
}
[4814] Fix | Delete
[4815] Fix | Delete
return $post_id;
[4816] Fix | Delete
}
[4817] Fix | Delete
[4818] Fix | Delete
if ( $update ) {
[4819] Fix | Delete
/**
[4820] Fix | Delete
* Fires once an existing post has been updated.
[4821] Fix | Delete
*
[4822] Fix | Delete
* The dynamic portion of the hook name, `$post->post_type`, refers to
[4823] Fix | Delete
* the post type slug.
[4824] Fix | Delete
*
[4825] Fix | Delete
* Possible hook names include:
[4826] Fix | Delete
*
[4827] Fix | Delete
* - `edit_post_post`
[4828] Fix | Delete
* - `edit_post_page`
[4829] Fix | Delete
*
[4830] Fix | Delete
* @since 5.1.0
[4831] Fix | Delete
*
[4832] Fix | Delete
* @param int $post_id Post ID.
[4833] Fix | Delete
* @param WP_Post $post Post object.
[4834] Fix | Delete
*/
[4835] Fix | Delete
do_action( "edit_post_{$post->post_type}", $post_id, $post );
[4836] Fix | Delete
[4837] Fix | Delete
/**
[4838] Fix | Delete
* Fires once an existing post has been updated.
[4839] Fix | Delete
*
[4840] Fix | Delete
* @since 1.2.0
[4841] Fix | Delete
*
[4842] Fix | Delete
* @param int $post_id Post ID.
[4843] Fix | Delete
* @param WP_Post $post Post object.
[4844] Fix | Delete
*/
[4845] Fix | Delete
do_action( 'edit_post', $post_id, $post );
[4846] Fix | Delete
[4847] Fix | Delete
$post_after = get_post( $post_id );
[4848] Fix | Delete
[4849] Fix | Delete
/**
[4850] Fix | Delete
* Fires once an existing post has been updated.
[4851] Fix | Delete
*
[4852] Fix | Delete
* @since 3.0.0
[4853] Fix | Delete
*
[4854] Fix | Delete
* @param int $post_id Post ID.
[4855] Fix | Delete
* @param WP_Post $post_after Post object following the update.
[4856] Fix | Delete
* @param WP_Post $post_before Post object before the update.
[4857] Fix | Delete
*/
[4858] Fix | Delete
do_action( 'post_updated', $post_id, $post_after, $post_before );
[4859] Fix | Delete
}
[4860] Fix | Delete
[4861] Fix | Delete
/**
[4862] Fix | Delete
* Fires once a post has been saved.
[4863] Fix | Delete
*
[4864] Fix | Delete
* The dynamic portion of the hook name, `$post->post_type`, refers to
[4865] Fix | Delete
* the post type slug.
[4866] Fix | Delete
*
[4867] Fix | Delete
* Possible hook names include:
[4868] Fix | Delete
*
[4869] Fix | Delete
* - `save_post_post`
[4870] Fix | Delete
* - `save_post_page`
[4871] Fix | Delete
*
[4872] Fix | Delete
* @since 3.7.0
[4873] Fix | Delete
*
[4874] Fix | Delete
* @param int $post_id Post ID.
[4875] Fix | Delete
* @param WP_Post $post Post object.
[4876] Fix | Delete
* @param bool $update Whether this is an existing post being updated.
[4877] Fix | Delete
*/
[4878] Fix | Delete
do_action( "save_post_{$post->post_type}", $post_id, $post, $update );
[4879] Fix | Delete
[4880] Fix | Delete
/**
[4881] Fix | Delete
* Fires once a post has been saved.
[4882] Fix | Delete
*
[4883] Fix | Delete
* @since 1.5.0
[4884] Fix | Delete
*
[4885] Fix | Delete
* @param int $post_id Post ID.
[4886] Fix | Delete
* @param WP_Post $post Post object.
[4887] Fix | Delete
* @param bool $update Whether this is an existing post being updated.
[4888] Fix | Delete
*/
[4889] Fix | Delete
do_action( 'save_post', $post_id, $post, $update );
[4890] Fix | Delete
[4891] Fix | Delete
/**
[4892] Fix | Delete
* Fires once a post has been saved.
[4893] Fix | Delete
*
[4894] Fix | Delete
* @since 2.0.0
[4895] Fix | Delete
*
[4896] Fix | Delete
* @param int $post_id Post ID.
[4897] Fix | Delete
* @param WP_Post $post Post object.
[4898] Fix | Delete
* @param bool $update Whether this is an existing post being updated.
[4899] Fix | Delete
*/
[4900] Fix | Delete
do_action( 'wp_insert_post', $post_id, $post, $update );
[4901] Fix | Delete
[4902] Fix | Delete
if ( $fire_after_hooks ) {
[4903] Fix | Delete
wp_after_insert_post( $post, $update, $post_before );
[4904] Fix | Delete
}
[4905] Fix | Delete
[4906] Fix | Delete
return $post_id;
[4907] Fix | Delete
}
[4908] Fix | Delete
[4909] Fix | Delete
/**
[4910] Fix | Delete
* Updates a post with new post data.
[4911] Fix | Delete
*
[4912] Fix | Delete
* The date does not have to be set for drafts. You can set the date and it will
[4913] Fix | Delete
* not be overridden.
[4914] Fix | Delete
*
[4915] Fix | Delete
* @since 1.0.0
[4916] Fix | Delete
* @since 3.5.0 Added the `$wp_error` parameter to allow a WP_Error to be returned on failure.
[4917] Fix | Delete
* @since 5.6.0 Added the `$fire_after_hooks` parameter.
[4918] Fix | Delete
*
[4919] Fix | Delete
* @param array|object $postarr Optional. Post data. Arrays are expected to be escaped,
[4920] Fix | Delete
* objects are not. See wp_insert_post() for accepted arguments.
[4921] Fix | Delete
* Default array.
[4922] Fix | Delete
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
[4923] Fix | Delete
* @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true.
[4924] Fix | Delete
* @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure.
[4925] Fix | Delete
*/
[4926] Fix | Delete
function wp_update_post( $postarr = array(), $wp_error = false, $fire_after_hooks = true ) {
[4927] Fix | Delete
if ( is_object( $postarr ) ) {
[4928] Fix | Delete
// Non-escaped post was passed.
[4929] Fix | Delete
$postarr = get_object_vars( $postarr );
[4930] Fix | Delete
$postarr = wp_slash( $postarr );
[4931] Fix | Delete
}
[4932] Fix | Delete
[4933] Fix | Delete
// First, get all of the original fields.
[4934] Fix | Delete
$post = get_post( $postarr['ID'], ARRAY_A );
[4935] Fix | Delete
[4936] Fix | Delete
if ( is_null( $post ) ) {
[4937] Fix | Delete
if ( $wp_error ) {
[4938] Fix | Delete
return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
[4939] Fix | Delete
}
[4940] Fix | Delete
return 0;
[4941] Fix | Delete
}
[4942] Fix | Delete
[4943] Fix | Delete
// Escape data pulled from DB.
[4944] Fix | Delete
$post = wp_slash( $post );
[4945] Fix | Delete
[4946] Fix | Delete
// Passed post category list overwrites existing category list if not empty.
[4947] Fix | Delete
if ( isset( $postarr['post_category'] ) && is_array( $postarr['post_category'] )
[4948] Fix | Delete
&& count( $postarr['post_category'] ) > 0
[4949] Fix | Delete
) {
[4950] Fix | Delete
$post_cats = $postarr['post_category'];
[4951] Fix | Delete
} else {
[4952] Fix | Delete
$post_cats = $post['post_category'];
[4953] Fix | Delete
}
[4954] Fix | Delete
[4955] Fix | Delete
// Drafts shouldn't be assigned a date unless explicitly done so by the user.
[4956] Fix | Delete
if ( isset( $post['post_status'] )
[4957] Fix | Delete
&& in_array( $post['post_status'], array( 'draft', 'pending', 'auto-draft' ), true )
[4958] Fix | Delete
&& empty( $postarr['edit_date'] ) && ( '0000-00-00 00:00:00' === $post['post_date_gmt'] )
[4959] Fix | Delete
) {
[4960] Fix | Delete
$clear_date = true;
[4961] Fix | Delete
} else {
[4962] Fix | Delete
$clear_date = false;
[4963] Fix | Delete
}
[4964] Fix | Delete
[4965] Fix | Delete
// Merge old and new fields with new fields overwriting old ones.
[4966] Fix | Delete
$postarr = array_merge( $post, $postarr );
[4967] Fix | Delete
$postarr['post_category'] = $post_cats;
[4968] Fix | Delete
if ( $clear_date ) {
[4969] Fix | Delete
$postarr['post_date'] = current_time( 'mysql' );
[4970] Fix | Delete
$postarr['post_date_gmt'] = '';
[4971] Fix | Delete
}
[4972] Fix | Delete
[4973] Fix | Delete
if ( 'attachment' === $postarr['post_type'] ) {
[4974] Fix | Delete
return wp_insert_attachment( $postarr, false, 0, $wp_error );
[4975] Fix | Delete
}
[4976] Fix | Delete
[4977] Fix | Delete
// Discard 'tags_input' parameter if it's the same as existing post tags.
[4978] Fix | Delete
if ( isset( $postarr['tags_input'] ) && is_object_in_taxonomy( $postarr['post_type'], 'post_tag' ) ) {
[4979] Fix | Delete
$tags = get_the_terms( $postarr['ID'], 'post_tag' );
[4980] Fix | Delete
$tag_names = array();
[4981] Fix | Delete
[4982] Fix | Delete
if ( $tags && ! is_wp_error( $tags ) ) {
[4983] Fix | Delete
$tag_names = wp_list_pluck( $tags, 'name' );
[4984] Fix | Delete
}
[4985] Fix | Delete
[4986] Fix | Delete
if ( $postarr['tags_input'] === $tag_names ) {
[4987] Fix | Delete
unset( $postarr['tags_input'] );
[4988] Fix | Delete
}
[4989] Fix | Delete
}
[4990] Fix | Delete
[4991] Fix | Delete
return wp_insert_post( $postarr, $wp_error, $fire_after_hooks );
[4992] Fix | Delete
}
[4993] Fix | Delete
[4994] Fix | Delete
/**
[4995] Fix | Delete
* Publishes a post by transitioning the post status.
[4996] Fix | Delete
*
[4997] Fix | Delete
* @since 2.1.0
[4998] Fix | Delete
*
[4999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function