Edit File by line
/home/barbar84/www/wp-inclu...
File: post.php
*/
[3500] Fix | Delete
function wp_untrash_post_comments( $post = null ) {
[3501] Fix | Delete
global $wpdb;
[3502] Fix | Delete
[3503] Fix | Delete
$post = get_post( $post );
[3504] Fix | Delete
[3505] Fix | Delete
if ( ! $post ) {
[3506] Fix | Delete
return;
[3507] Fix | Delete
}
[3508] Fix | Delete
[3509] Fix | Delete
$post_id = $post->ID;
[3510] Fix | Delete
[3511] Fix | Delete
$statuses = get_post_meta( $post_id, '_wp_trash_meta_comments_status', true );
[3512] Fix | Delete
[3513] Fix | Delete
if ( ! $statuses ) {
[3514] Fix | Delete
return true;
[3515] Fix | Delete
}
[3516] Fix | Delete
[3517] Fix | Delete
/**
[3518] Fix | Delete
* Fires before comments are restored for a post from the Trash.
[3519] Fix | Delete
*
[3520] Fix | Delete
* @since 2.9.0
[3521] Fix | Delete
*
[3522] Fix | Delete
* @param int $post_id Post ID.
[3523] Fix | Delete
*/
[3524] Fix | Delete
do_action( 'untrash_post_comments', $post_id );
[3525] Fix | Delete
[3526] Fix | Delete
// Restore each comment to its original status.
[3527] Fix | Delete
$group_by_status = array();
[3528] Fix | Delete
foreach ( $statuses as $comment_id => $comment_status ) {
[3529] Fix | Delete
$group_by_status[ $comment_status ][] = $comment_id;
[3530] Fix | Delete
}
[3531] Fix | Delete
[3532] Fix | Delete
foreach ( $group_by_status as $status => $comments ) {
[3533] Fix | Delete
// Sanity check. This shouldn't happen.
[3534] Fix | Delete
if ( 'post-trashed' === $status ) {
[3535] Fix | Delete
$status = '0';
[3536] Fix | Delete
}
[3537] Fix | Delete
$comments_in = implode( ', ', array_map( 'intval', $comments ) );
[3538] Fix | Delete
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->comments SET comment_approved = %s WHERE comment_ID IN ($comments_in)", $status ) );
[3539] Fix | Delete
}
[3540] Fix | Delete
[3541] Fix | Delete
clean_comment_cache( array_keys( $statuses ) );
[3542] Fix | Delete
[3543] Fix | Delete
delete_post_meta( $post_id, '_wp_trash_meta_comments_status' );
[3544] Fix | Delete
[3545] Fix | Delete
/**
[3546] Fix | Delete
* Fires after comments are restored for a post from the Trash.
[3547] Fix | Delete
*
[3548] Fix | Delete
* @since 2.9.0
[3549] Fix | Delete
*
[3550] Fix | Delete
* @param int $post_id Post ID.
[3551] Fix | Delete
*/
[3552] Fix | Delete
do_action( 'untrashed_post_comments', $post_id );
[3553] Fix | Delete
}
[3554] Fix | Delete
[3555] Fix | Delete
/**
[3556] Fix | Delete
* Retrieve the list of categories for a post.
[3557] Fix | Delete
*
[3558] Fix | Delete
* Compatibility layer for themes and plugins. Also an easy layer of abstraction
[3559] Fix | Delete
* away from the complexity of the taxonomy layer.
[3560] Fix | Delete
*
[3561] Fix | Delete
* @since 2.1.0
[3562] Fix | Delete
*
[3563] Fix | Delete
* @see wp_get_object_terms()
[3564] Fix | Delete
*
[3565] Fix | Delete
* @param int $post_id Optional. The Post ID. Does not default to the ID of the
[3566] Fix | Delete
* global $post. Default 0.
[3567] Fix | Delete
* @param array $args Optional. Category query parameters. Default empty array.
[3568] Fix | Delete
* See WP_Term_Query::__construct() for supported arguments.
[3569] Fix | Delete
* @return array|WP_Error List of categories. If the `$fields` argument passed via `$args` is 'all' or
[3570] Fix | Delete
* 'all_with_object_id', an array of WP_Term objects will be returned. If `$fields`
[3571] Fix | Delete
* is 'ids', an array of category IDs. If `$fields` is 'names', an array of category names.
[3572] Fix | Delete
* WP_Error object if 'category' taxonomy doesn't exist.
[3573] Fix | Delete
*/
[3574] Fix | Delete
function wp_get_post_categories( $post_id = 0, $args = array() ) {
[3575] Fix | Delete
$post_id = (int) $post_id;
[3576] Fix | Delete
[3577] Fix | Delete
$defaults = array( 'fields' => 'ids' );
[3578] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[3579] Fix | Delete
[3580] Fix | Delete
$cats = wp_get_object_terms( $post_id, 'category', $args );
[3581] Fix | Delete
return $cats;
[3582] Fix | Delete
}
[3583] Fix | Delete
[3584] Fix | Delete
/**
[3585] Fix | Delete
* Retrieve the tags for a post.
[3586] Fix | Delete
*
[3587] Fix | Delete
* There is only one default for this function, called 'fields' and by default
[3588] Fix | Delete
* is set to 'all'. There are other defaults that can be overridden in
[3589] Fix | Delete
* wp_get_object_terms().
[3590] Fix | Delete
*
[3591] Fix | Delete
* @since 2.3.0
[3592] Fix | Delete
*
[3593] Fix | Delete
* @param int $post_id Optional. The Post ID. Does not default to the ID of the
[3594] Fix | Delete
* global $post. Default 0.
[3595] Fix | Delete
* @param array $args Optional. Tag query parameters. Default empty array.
[3596] Fix | Delete
* See WP_Term_Query::__construct() for supported arguments.
[3597] Fix | Delete
* @return array|WP_Error Array of WP_Term objects on success or empty array if no tags were found.
[3598] Fix | Delete
* WP_Error object if 'post_tag' taxonomy doesn't exist.
[3599] Fix | Delete
*/
[3600] Fix | Delete
function wp_get_post_tags( $post_id = 0, $args = array() ) {
[3601] Fix | Delete
return wp_get_post_terms( $post_id, 'post_tag', $args );
[3602] Fix | Delete
}
[3603] Fix | Delete
[3604] Fix | Delete
/**
[3605] Fix | Delete
* Retrieves the terms for a post.
[3606] Fix | Delete
*
[3607] Fix | Delete
* @since 2.8.0
[3608] Fix | Delete
*
[3609] Fix | Delete
* @param int $post_id Optional. The Post ID. Does not default to the ID of the
[3610] Fix | Delete
* global $post. Default 0.
[3611] Fix | Delete
* @param string|string[] $taxonomy Optional. The taxonomy slug or array of slugs for which
[3612] Fix | Delete
* to retrieve terms. Default 'post_tag'.
[3613] Fix | Delete
* @param array $args {
[3614] Fix | Delete
* Optional. Term query parameters. See WP_Term_Query::__construct() for supported arguments.
[3615] Fix | Delete
*
[3616] Fix | Delete
* @type string $fields Term fields to retrieve. Default 'all'.
[3617] Fix | Delete
* }
[3618] Fix | Delete
* @return array|WP_Error Array of WP_Term objects on success or empty array if no terms were found.
[3619] Fix | Delete
* WP_Error object if `$taxonomy` doesn't exist.
[3620] Fix | Delete
*/
[3621] Fix | Delete
function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array() ) {
[3622] Fix | Delete
$post_id = (int) $post_id;
[3623] Fix | Delete
[3624] Fix | Delete
$defaults = array( 'fields' => 'all' );
[3625] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[3626] Fix | Delete
[3627] Fix | Delete
$tags = wp_get_object_terms( $post_id, $taxonomy, $args );
[3628] Fix | Delete
[3629] Fix | Delete
return $tags;
[3630] Fix | Delete
}
[3631] Fix | Delete
[3632] Fix | Delete
/**
[3633] Fix | Delete
* Retrieve a number of recent posts.
[3634] Fix | Delete
*
[3635] Fix | Delete
* @since 1.0.0
[3636] Fix | Delete
*
[3637] Fix | Delete
* @see get_posts()
[3638] Fix | Delete
*
[3639] Fix | Delete
* @param array $args Optional. Arguments to retrieve posts. Default empty array.
[3640] Fix | Delete
* @param string $output Optional. The required return type. One of OBJECT or ARRAY_A, which
[3641] Fix | Delete
* correspond to a WP_Post object or an associative array, respectively.
[3642] Fix | Delete
* Default ARRAY_A.
[3643] Fix | Delete
* @return array|false Array of recent posts, where the type of each element is determined
[3644] Fix | Delete
* by the `$output` parameter. Empty array on failure.
[3645] Fix | Delete
*/
[3646] Fix | Delete
function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {
[3647] Fix | Delete
[3648] Fix | Delete
if ( is_numeric( $args ) ) {
[3649] Fix | Delete
_deprecated_argument( __FUNCTION__, '3.1.0', __( 'Passing an integer number of posts is deprecated. Pass an array of arguments instead.' ) );
[3650] Fix | Delete
$args = array( 'numberposts' => absint( $args ) );
[3651] Fix | Delete
}
[3652] Fix | Delete
[3653] Fix | Delete
// Set default arguments.
[3654] Fix | Delete
$defaults = array(
[3655] Fix | Delete
'numberposts' => 10,
[3656] Fix | Delete
'offset' => 0,
[3657] Fix | Delete
'category' => 0,
[3658] Fix | Delete
'orderby' => 'post_date',
[3659] Fix | Delete
'order' => 'DESC',
[3660] Fix | Delete
'include' => '',
[3661] Fix | Delete
'exclude' => '',
[3662] Fix | Delete
'meta_key' => '',
[3663] Fix | Delete
'meta_value' => '',
[3664] Fix | Delete
'post_type' => 'post',
[3665] Fix | Delete
'post_status' => 'draft, publish, future, pending, private',
[3666] Fix | Delete
'suppress_filters' => true,
[3667] Fix | Delete
);
[3668] Fix | Delete
[3669] Fix | Delete
$parsed_args = wp_parse_args( $args, $defaults );
[3670] Fix | Delete
[3671] Fix | Delete
$results = get_posts( $parsed_args );
[3672] Fix | Delete
[3673] Fix | Delete
// Backward compatibility. Prior to 3.1 expected posts to be returned in array.
[3674] Fix | Delete
if ( ARRAY_A == $output ) {
[3675] Fix | Delete
foreach ( $results as $key => $result ) {
[3676] Fix | Delete
$results[ $key ] = get_object_vars( $result );
[3677] Fix | Delete
}
[3678] Fix | Delete
return $results ? $results : array();
[3679] Fix | Delete
}
[3680] Fix | Delete
[3681] Fix | Delete
return $results ? $results : false;
[3682] Fix | Delete
[3683] Fix | Delete
}
[3684] Fix | Delete
[3685] Fix | Delete
/**
[3686] Fix | Delete
* Insert or update a post.
[3687] Fix | Delete
*
[3688] Fix | Delete
* If the $postarr parameter has 'ID' set to a value, then post will be updated.
[3689] Fix | Delete
*
[3690] Fix | Delete
* You can set the post date manually, by setting the values for 'post_date'
[3691] Fix | Delete
* and 'post_date_gmt' keys. You can close the comments or open the comments by
[3692] Fix | Delete
* setting the value for 'comment_status' key.
[3693] Fix | Delete
*
[3694] Fix | Delete
* @since 1.0.0
[3695] Fix | Delete
* @since 2.6.0 Added the `$wp_error` parameter to allow a WP_Error to be returned on failure.
[3696] Fix | Delete
* @since 4.2.0 Support was added for encoding emoji in the post title, content, and excerpt.
[3697] Fix | Delete
* @since 4.4.0 A 'meta_input' array can now be passed to `$postarr` to add post meta data.
[3698] Fix | Delete
* @since 5.6.0 Added the `$fire_after_hooks` parameter.
[3699] Fix | Delete
*
[3700] Fix | Delete
* @see sanitize_post()
[3701] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[3702] Fix | Delete
*
[3703] Fix | Delete
* @param array $postarr {
[3704] Fix | Delete
* An array of elements that make up a post to update or insert.
[3705] Fix | Delete
*
[3706] Fix | Delete
* @type int $ID The post ID. If equal to something other than 0,
[3707] Fix | Delete
* the post with that ID will be updated. Default 0.
[3708] Fix | Delete
* @type int $post_author The ID of the user who added the post. Default is
[3709] Fix | Delete
* the current user ID.
[3710] Fix | Delete
* @type string $post_date The date of the post. Default is the current time.
[3711] Fix | Delete
* @type string $post_date_gmt The date of the post in the GMT timezone. Default is
[3712] Fix | Delete
* the value of `$post_date`.
[3713] Fix | Delete
* @type mixed $post_content The post content. Default empty.
[3714] Fix | Delete
* @type string $post_content_filtered The filtered post content. Default empty.
[3715] Fix | Delete
* @type string $post_title The post title. Default empty.
[3716] Fix | Delete
* @type string $post_excerpt The post excerpt. Default empty.
[3717] Fix | Delete
* @type string $post_status The post status. Default 'draft'.
[3718] Fix | Delete
* @type string $post_type The post type. Default 'post'.
[3719] Fix | Delete
* @type string $comment_status Whether the post can accept comments. Accepts 'open' or 'closed'.
[3720] Fix | Delete
* Default is the value of 'default_comment_status' option.
[3721] Fix | Delete
* @type string $ping_status Whether the post can accept pings. Accepts 'open' or 'closed'.
[3722] Fix | Delete
* Default is the value of 'default_ping_status' option.
[3723] Fix | Delete
* @type string $post_password The password to access the post. Default empty.
[3724] Fix | Delete
* @type string $post_name The post name. Default is the sanitized post title
[3725] Fix | Delete
* when creating a new post.
[3726] Fix | Delete
* @type string $to_ping Space or carriage return-separated list of URLs to ping.
[3727] Fix | Delete
* Default empty.
[3728] Fix | Delete
* @type string $pinged Space or carriage return-separated list of URLs that have
[3729] Fix | Delete
* been pinged. Default empty.
[3730] Fix | Delete
* @type string $post_modified The date when the post was last modified. Default is
[3731] Fix | Delete
* the current time.
[3732] Fix | Delete
* @type string $post_modified_gmt The date when the post was last modified in the GMT
[3733] Fix | Delete
* timezone. Default is the current time.
[3734] Fix | Delete
* @type int $post_parent Set this for the post it belongs to, if any. Default 0.
[3735] Fix | Delete
* @type int $menu_order The order the post should be displayed in. Default 0.
[3736] Fix | Delete
* @type string $post_mime_type The mime type of the post. Default empty.
[3737] Fix | Delete
* @type string $guid Global Unique ID for referencing the post. Default empty.
[3738] Fix | Delete
* @type int[] $post_category Array of category IDs.
[3739] Fix | Delete
* Defaults to value of the 'default_category' option.
[3740] Fix | Delete
* @type array $tags_input Array of tag names, slugs, or IDs. Default empty.
[3741] Fix | Delete
* @type array $tax_input Array of taxonomy terms keyed by their taxonomy name. Default empty.
[3742] Fix | Delete
* @type array $meta_input Array of post meta values keyed by their post meta key. Default empty.
[3743] Fix | Delete
* }
[3744] Fix | Delete
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
[3745] Fix | Delete
* @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true.
[3746] Fix | Delete
* @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure.
[3747] Fix | Delete
*/
[3748] Fix | Delete
function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true ) {
[3749] Fix | Delete
global $wpdb;
[3750] Fix | Delete
[3751] Fix | Delete
// Capture original pre-sanitized array for passing into filters.
[3752] Fix | Delete
$unsanitized_postarr = $postarr;
[3753] Fix | Delete
[3754] Fix | Delete
$user_id = get_current_user_id();
[3755] Fix | Delete
[3756] Fix | Delete
$defaults = array(
[3757] Fix | Delete
'post_author' => $user_id,
[3758] Fix | Delete
'post_content' => '',
[3759] Fix | Delete
'post_content_filtered' => '',
[3760] Fix | Delete
'post_title' => '',
[3761] Fix | Delete
'post_excerpt' => '',
[3762] Fix | Delete
'post_status' => 'draft',
[3763] Fix | Delete
'post_type' => 'post',
[3764] Fix | Delete
'comment_status' => '',
[3765] Fix | Delete
'ping_status' => '',
[3766] Fix | Delete
'post_password' => '',
[3767] Fix | Delete
'to_ping' => '',
[3768] Fix | Delete
'pinged' => '',
[3769] Fix | Delete
'post_parent' => 0,
[3770] Fix | Delete
'menu_order' => 0,
[3771] Fix | Delete
'guid' => '',
[3772] Fix | Delete
'import_id' => 0,
[3773] Fix | Delete
'context' => '',
[3774] Fix | Delete
'post_date' => '',
[3775] Fix | Delete
'post_date_gmt' => '',
[3776] Fix | Delete
);
[3777] Fix | Delete
[3778] Fix | Delete
$postarr = wp_parse_args( $postarr, $defaults );
[3779] Fix | Delete
[3780] Fix | Delete
unset( $postarr['filter'] );
[3781] Fix | Delete
[3782] Fix | Delete
$postarr = sanitize_post( $postarr, 'db' );
[3783] Fix | Delete
[3784] Fix | Delete
// Are we updating or creating?
[3785] Fix | Delete
$post_ID = 0;
[3786] Fix | Delete
$update = false;
[3787] Fix | Delete
$guid = $postarr['guid'];
[3788] Fix | Delete
[3789] Fix | Delete
if ( ! empty( $postarr['ID'] ) ) {
[3790] Fix | Delete
$update = true;
[3791] Fix | Delete
[3792] Fix | Delete
// Get the post ID and GUID.
[3793] Fix | Delete
$post_ID = $postarr['ID'];
[3794] Fix | Delete
$post_before = get_post( $post_ID );
[3795] Fix | Delete
[3796] Fix | Delete
if ( is_null( $post_before ) ) {
[3797] Fix | Delete
if ( $wp_error ) {
[3798] Fix | Delete
return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
[3799] Fix | Delete
}
[3800] Fix | Delete
return 0;
[3801] Fix | Delete
}
[3802] Fix | Delete
[3803] Fix | Delete
$guid = get_post_field( 'guid', $post_ID );
[3804] Fix | Delete
$previous_status = get_post_field( 'post_status', $post_ID );
[3805] Fix | Delete
} else {
[3806] Fix | Delete
$previous_status = 'new';
[3807] Fix | Delete
$post_before = null;
[3808] Fix | Delete
}
[3809] Fix | Delete
[3810] Fix | Delete
$post_type = empty( $postarr['post_type'] ) ? 'post' : $postarr['post_type'];
[3811] Fix | Delete
[3812] Fix | Delete
$post_title = $postarr['post_title'];
[3813] Fix | Delete
$post_content = $postarr['post_content'];
[3814] Fix | Delete
$post_excerpt = $postarr['post_excerpt'];
[3815] Fix | Delete
[3816] Fix | Delete
if ( isset( $postarr['post_name'] ) ) {
[3817] Fix | Delete
$post_name = $postarr['post_name'];
[3818] Fix | Delete
} elseif ( $update ) {
[3819] Fix | Delete
// For an update, don't modify the post_name if it wasn't supplied as an argument.
[3820] Fix | Delete
$post_name = $post_before->post_name;
[3821] Fix | Delete
}
[3822] Fix | Delete
[3823] Fix | Delete
$maybe_empty = 'attachment' !== $post_type
[3824] Fix | Delete
&& ! $post_content && ! $post_title && ! $post_excerpt
[3825] Fix | Delete
&& post_type_supports( $post_type, 'editor' )
[3826] Fix | Delete
&& post_type_supports( $post_type, 'title' )
[3827] Fix | Delete
&& post_type_supports( $post_type, 'excerpt' );
[3828] Fix | Delete
[3829] Fix | Delete
/**
[3830] Fix | Delete
* Filters whether the post should be considered "empty".
[3831] Fix | Delete
*
[3832] Fix | Delete
* The post is considered "empty" if both:
[3833] Fix | Delete
* 1. The post type supports the title, editor, and excerpt fields
[3834] Fix | Delete
* 2. The title, editor, and excerpt fields are all empty
[3835] Fix | Delete
*
[3836] Fix | Delete
* Returning a truthy value from the filter will effectively short-circuit
[3837] Fix | Delete
* the new post being inserted and return 0. If $wp_error is true, a WP_Error
[3838] Fix | Delete
* will be returned instead.
[3839] Fix | Delete
*
[3840] Fix | Delete
* @since 3.3.0
[3841] Fix | Delete
*
[3842] Fix | Delete
* @param bool $maybe_empty Whether the post should be considered "empty".
[3843] Fix | Delete
* @param array $postarr Array of post data.
[3844] Fix | Delete
*/
[3845] Fix | Delete
if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
[3846] Fix | Delete
if ( $wp_error ) {
[3847] Fix | Delete
return new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) );
[3848] Fix | Delete
} else {
[3849] Fix | Delete
return 0;
[3850] Fix | Delete
}
[3851] Fix | Delete
}
[3852] Fix | Delete
[3853] Fix | Delete
$post_status = empty( $postarr['post_status'] ) ? 'draft' : $postarr['post_status'];
[3854] Fix | Delete
[3855] Fix | Delete
if ( 'attachment' === $post_type && ! in_array( $post_status, array( 'inherit', 'private', 'trash', 'auto-draft' ), true ) ) {
[3856] Fix | Delete
$post_status = 'inherit';
[3857] Fix | Delete
}
[3858] Fix | Delete
[3859] Fix | Delete
if ( ! empty( $postarr['post_category'] ) ) {
[3860] Fix | Delete
// Filter out empty terms.
[3861] Fix | Delete
$post_category = array_filter( $postarr['post_category'] );
[3862] Fix | Delete
}
[3863] Fix | Delete
[3864] Fix | Delete
// Make sure we set a valid category.
[3865] Fix | Delete
if ( empty( $post_category ) || 0 === count( $post_category ) || ! is_array( $post_category ) ) {
[3866] Fix | Delete
// 'post' requires at least one category.
[3867] Fix | Delete
if ( 'post' === $post_type && 'auto-draft' !== $post_status ) {
[3868] Fix | Delete
$post_category = array( get_option( 'default_category' ) );
[3869] Fix | Delete
} else {
[3870] Fix | Delete
$post_category = array();
[3871] Fix | Delete
}
[3872] Fix | Delete
}
[3873] Fix | Delete
[3874] Fix | Delete
/*
[3875] Fix | Delete
* Don't allow contributors to set the post slug for pending review posts.
[3876] Fix | Delete
*
[3877] Fix | Delete
* For new posts check the primitive capability, for updates check the meta capability.
[3878] Fix | Delete
*/
[3879] Fix | Delete
$post_type_object = get_post_type_object( $post_type );
[3880] Fix | Delete
[3881] Fix | Delete
if ( ! $update && 'pending' === $post_status && ! current_user_can( $post_type_object->cap->publish_posts ) ) {
[3882] Fix | Delete
$post_name = '';
[3883] Fix | Delete
} elseif ( $update && 'pending' === $post_status && ! current_user_can( 'publish_post', $post_ID ) ) {
[3884] Fix | Delete
$post_name = '';
[3885] Fix | Delete
}
[3886] Fix | Delete
[3887] Fix | Delete
/*
[3888] Fix | Delete
* Create a valid post name. Drafts and pending posts are allowed to have
[3889] Fix | Delete
* an empty post name.
[3890] Fix | Delete
*/
[3891] Fix | Delete
if ( empty( $post_name ) ) {
[3892] Fix | Delete
if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ), true ) ) {
[3893] Fix | Delete
$post_name = sanitize_title( $post_title );
[3894] Fix | Delete
} else {
[3895] Fix | Delete
$post_name = '';
[3896] Fix | Delete
}
[3897] Fix | Delete
} else {
[3898] Fix | Delete
// On updates, we need to check to see if it's using the old, fixed sanitization context.
[3899] Fix | Delete
$check_name = sanitize_title( $post_name, '', 'old-save' );
[3900] Fix | Delete
[3901] Fix | Delete
if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && get_post_field( 'post_name', $post_ID ) == $check_name ) {
[3902] Fix | Delete
$post_name = $check_name;
[3903] Fix | Delete
} else { // new post, or slug has changed.
[3904] Fix | Delete
$post_name = sanitize_title( $post_name );
[3905] Fix | Delete
}
[3906] Fix | Delete
}
[3907] Fix | Delete
[3908] Fix | Delete
/*
[3909] Fix | Delete
* Resolve the post date from any provided post date or post date GMT strings;
[3910] Fix | Delete
* if none are provided, the date will be set to now.
[3911] Fix | Delete
*/
[3912] Fix | Delete
$post_date = wp_resolve_post_date( $postarr['post_date'], $postarr['post_date_gmt'] );
[3913] Fix | Delete
if ( ! $post_date ) {
[3914] Fix | Delete
if ( $wp_error ) {
[3915] Fix | Delete
return new WP_Error( 'invalid_date', __( 'Invalid date.' ) );
[3916] Fix | Delete
} else {
[3917] Fix | Delete
return 0;
[3918] Fix | Delete
}
[3919] Fix | Delete
}
[3920] Fix | Delete
[3921] Fix | Delete
if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_date_gmt'] ) {
[3922] Fix | Delete
if ( ! in_array( $post_status, get_post_stati( array( 'date_floating' => true ) ), true ) ) {
[3923] Fix | Delete
$post_date_gmt = get_gmt_from_date( $post_date );
[3924] Fix | Delete
} else {
[3925] Fix | Delete
$post_date_gmt = '0000-00-00 00:00:00';
[3926] Fix | Delete
}
[3927] Fix | Delete
} else {
[3928] Fix | Delete
$post_date_gmt = $postarr['post_date_gmt'];
[3929] Fix | Delete
}
[3930] Fix | Delete
[3931] Fix | Delete
if ( $update || '0000-00-00 00:00:00' === $post_date ) {
[3932] Fix | Delete
$post_modified = current_time( 'mysql' );
[3933] Fix | Delete
$post_modified_gmt = current_time( 'mysql', 1 );
[3934] Fix | Delete
} else {
[3935] Fix | Delete
$post_modified = $post_date;
[3936] Fix | Delete
$post_modified_gmt = $post_date_gmt;
[3937] Fix | Delete
}
[3938] Fix | Delete
[3939] Fix | Delete
if ( 'attachment' !== $post_type ) {
[3940] Fix | Delete
$now = gmdate( 'Y-m-d H:i:s' );
[3941] Fix | Delete
[3942] Fix | Delete
if ( 'publish' === $post_status ) {
[3943] Fix | Delete
if ( strtotime( $post_date_gmt ) - strtotime( $now ) >= MINUTE_IN_SECONDS ) {
[3944] Fix | Delete
$post_status = 'future';
[3945] Fix | Delete
}
[3946] Fix | Delete
} elseif ( 'future' === $post_status ) {
[3947] Fix | Delete
if ( strtotime( $post_date_gmt ) - strtotime( $now ) < MINUTE_IN_SECONDS ) {
[3948] Fix | Delete
$post_status = 'publish';
[3949] Fix | Delete
}
[3950] Fix | Delete
}
[3951] Fix | Delete
}
[3952] Fix | Delete
[3953] Fix | Delete
// Comment status.
[3954] Fix | Delete
if ( empty( $postarr['comment_status'] ) ) {
[3955] Fix | Delete
if ( $update ) {
[3956] Fix | Delete
$comment_status = 'closed';
[3957] Fix | Delete
} else {
[3958] Fix | Delete
$comment_status = get_default_comment_status( $post_type );
[3959] Fix | Delete
}
[3960] Fix | Delete
} else {
[3961] Fix | Delete
$comment_status = $postarr['comment_status'];
[3962] Fix | Delete
}
[3963] Fix | Delete
[3964] Fix | Delete
// These variables are needed by compact() later.
[3965] Fix | Delete
$post_content_filtered = $postarr['post_content_filtered'];
[3966] Fix | Delete
$post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;
[3967] Fix | Delete
$ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
[3968] Fix | Delete
$to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
[3969] Fix | Delete
$pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
[3970] Fix | Delete
$import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;
[3971] Fix | Delete
[3972] Fix | Delete
/*
[3973] Fix | Delete
* The 'wp_insert_post_parent' filter expects all variables to be present.
[3974] Fix | Delete
* Previously, these variables would have already been extracted
[3975] Fix | Delete
*/
[3976] Fix | Delete
if ( isset( $postarr['menu_order'] ) ) {
[3977] Fix | Delete
$menu_order = (int) $postarr['menu_order'];
[3978] Fix | Delete
} else {
[3979] Fix | Delete
$menu_order = 0;
[3980] Fix | Delete
}
[3981] Fix | Delete
[3982] Fix | Delete
$post_password = isset( $postarr['post_password'] ) ? $postarr['post_password'] : '';
[3983] Fix | Delete
if ( 'private' === $post_status ) {
[3984] Fix | Delete
$post_password = '';
[3985] Fix | Delete
}
[3986] Fix | Delete
[3987] Fix | Delete
if ( isset( $postarr['post_parent'] ) ) {
[3988] Fix | Delete
$post_parent = (int) $postarr['post_parent'];
[3989] Fix | Delete
} else {
[3990] Fix | Delete
$post_parent = 0;
[3991] Fix | Delete
}
[3992] Fix | Delete
[3993] Fix | Delete
$new_postarr = array_merge(
[3994] Fix | Delete
array(
[3995] Fix | Delete
'ID' => $post_ID,
[3996] Fix | Delete
),
[3997] Fix | Delete
compact( array_diff( array_keys( $defaults ), array( 'context', 'filter' ) ) )
[3998] Fix | Delete
);
[3999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function