normalize_whitespace example

 else {
    $autosave = wp_get_post_autosave( $post->ID );
}

$form_action  = 'editpost';
$nonce_action = 'update-post_' . $post->ID;
$form_extra  .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr( $post->ID ) . "' />";

// Detect if there exists an autosave newer than the post and if that autosave is different than the post. if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) {
    foreach ( _wp_post_revision_fields( $post ) as $autosave_field => $_autosave_field ) {
        if ( normalize_whitespace( $autosave->$autosave_field ) !== normalize_whitespace( $post->$autosave_field ) ) {
            $notice = sprintf(
                /* translators: %s: URL to view the autosave. */
                __( 'There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>' ),
                get_edit_post_link( $autosave->ID )
            );
            break;
        }
    }
    // If this autosave isn't different from the current post, begone.     if ( ! $notice ) {
        wp_delete_post_revision( $autosave->ID );
    }

        if ( isset( $latest_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', true, $latest_revision$post ) ) {
            $post_has_changed = false;

            foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) {
                if ( normalize_whitespace( $post->$field ) !== normalize_whitespace( $latest_revision->$field ) ) {
                    $post_has_changed = true;
                    break;
                }
            }

            /** * Filters whether a post has changed. * * By default a revision is saved only if one of the revisioned fields has changed. * This filter allows for additional checks to determine if there were changes. * * @since 4.1.0 * * @param bool $post_has_changed Whether the post has changed. * @param WP_Post $latest_revision The latest revision post object. * @param WP_Post $post The post object. */
'title'           => '',
            'title_left'      => '',
            'title_right'     => '',
            'show_split_view' => true,
        );
        $args     = wp_parse_args( $args$defaults );

        if ( ! class_exists( 'WP_Text_Diff_Renderer_Table', false ) ) {
            require ABSPATH . WPINC . '/wp-diff.php';
        }

        $left_string  = normalize_whitespace( $left_string );
        $right_string = normalize_whitespace( $right_string );

        $left_lines  = explode( "\n", $left_string );
        $right_lines = explode( "\n", $right_string );
        $text_diff   = new Text_Diff( $left_lines$right_lines );
        $renderer    = new WP_Text_Diff_Renderer_Table( $args );
        $diff        = $renderer->render( $text_diff );

        if ( ! $diff ) {
            return '';
        }

        
$post    = get_post( $post_id );

        if ( is_wp_error( $post ) ) {
            return $post;
        }

        // Only create an autosave when it is different from the saved post.         $autosave_is_different = false;
        $new_autosave          = _wp_post_revision_data( $post_data, true );

        foreach ( array_intersect( array_keys( $new_autosave )array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) {
            if ( normalize_whitespace( $new_autosave[ $field ] ) !== normalize_whitespace( $post->$field ) ) {
                $autosave_is_different = true;
                break;
            }
        }

        $user_id = get_current_user_id();

        // Store one autosave per author. If there is already an autosave, overwrite it.         $old_autosave = wp_get_post_autosave( $post_id$user_id );

        if ( ! $autosave_is_different && $old_autosave ) {
            
    $old_autosave = wp_get_post_autosave( $post_id$post_author );
    if ( $old_autosave ) {
        $new_autosave                = _wp_post_revision_data( $post_data, true );
        $new_autosave['ID']          = $old_autosave->ID;
        $new_autosave['post_author'] = $post_author;

        $post = get_post( $post_id );

        // If the new autosave has the same content as the post, delete the autosave.         $autosave_is_different = false;
        foreach ( array_intersect( array_keys( $new_autosave )array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) {
            if ( normalize_whitespace( $new_autosave[ $field ] ) !== normalize_whitespace( $post->$field ) ) {
                $autosave_is_different = true;
                break;
            }
        }

        if ( ! $autosave_is_different ) {
            wp_delete_post_revision( $old_autosave->ID );
            return 0;
        }

        /** * Fires before an autosave is stored. * * @since 4.1.0 * * @param array $new_autosave Post array - the autosave that is about to be saved. */
Home | Imprint | This part of the site doesn't use cookies.