Make WordPress Core

Ticket #11235: 11235.diff

File 11235.diff, 3.6 KB (added by swissspidy, 8 years ago)
  • src/wp-includes/default-filters.php

    diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
    index 3402e48..2cee88f 100644
    add_action( 'post_updated', 'wp_save_post_revision', 
    300300add_action( 'publish_post',               '_publish_post_hook',                       5, 1 );
    301301add_action( 'transition_post_status',     '_transition_post_status',                  5, 3 );
    302302add_action( 'transition_post_status',     '_update_term_count_on_transition_post_status', 10, 3 );
     303add_action( 'transition_post_status',     '_update_post_parents',                    10, 3 );
    303304add_action( 'comment_form',               'wp_comment_form_unfiltered_html_nonce'          );
    304305add_action( 'wp_scheduled_delete',        'wp_scheduled_delete'                            );
    305306add_action( 'wp_scheduled_auto_draft_delete', 'wp_delete_auto_drafts'                      );
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index c02108e..dae7dec 100644
    function wp_add_trashed_suffix_to_post_name_for_post( $post ) { 
    60736073        clean_post_cache( $post->ID );
    60746074        return $post_name;
    60756075}
     6076
     6077/**
     6078 * Removes the post's parent post in case the parent gets trashed.
     6079 *
     6080 * Stores the old value in post meta so that it can be re-added if the
     6081 * parent post is untrashed.
     6082 *
     6083 * @since 4.7.0
     6084 * @access private
     6085 *
     6086 * @global wpdb $wpdb WordPress database abstraction object.
     6087 *
     6088 * @param WP_Post $post Post object.
     6089 */
     6090function wp_remove_post_parent( $post ) {
     6091        global $wpdb;
     6092
     6093        $post = get_post( $post );
     6094
     6095        $previous_parent = $post->post_parent;
     6096
     6097        update_post_meta( $post->ID, '_wp_old_post_parent', $previous_parent );
     6098        $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $post->ID ) );
     6099        clean_post_cache( $post->ID );
     6100
     6101        do_action( 'wp_remove_post_parent', $post, $previous_parent );
     6102}
     6103
     6104/**
     6105 * Restores a posts' parent post in case the parent is untrashed.
     6106 *
     6107 * @since 4.7.0
     6108 * @access private
     6109 *
     6110 * @global wpdb $wpdb WordPress database abstraction object.
     6111 *
     6112 * @param WP_Post $post Post object.
     6113 */
     6114function wp_restore_post_parent( $post ) {
     6115        global $wpdb;
     6116
     6117        $post = get_post( $post );
     6118
     6119        $previous_parent = $post->post_parent;
     6120        $old_post_parent = (int) get_post_meta( $post->ID, '_wp_old_post_parent', true );
     6121
     6122        delete_post_meta( $post->ID, '_wp_old_post_parent' );
     6123
     6124        if ( 0 === $old_post_parent || 0 !== $previous_parent || ! get_post( $old_post_parent ) ) {
     6125                return;
     6126        }
     6127
     6128        $wpdb->update( $wpdb->posts, array( 'post_parent' => $post->post_parent ), array( 'ID' => $post->ID ) );
     6129        clean_post_cache( $post->ID );
     6130
     6131        do_action( 'wp_restore_post_parent', $post, $previous_parent );
     6132}
     6133
     6134/**
     6135 *
     6136 * @param string  $new_status New post status.
     6137 * @param string  $old_status Old post status.
     6138 * @param WP_Post $post       Post object.
     6139 */
     6140function _update_post_parents( $new_status, $old_status, $post ) {
     6141        if ( ! is_post_type_hierarchical( $post->post_type ) ) {
     6142                return;
     6143        }
     6144
     6145        if ( 'publish' !== $old_status && 'publish' === $new_status ) {
     6146                $children = get_posts( array(
     6147                        'fields'         => 'ids',
     6148                        'meta_key'       => '_wp_old_post_parent',
     6149                        'meta_value_num' => $post->ID,
     6150                        'post_type'      => $post->post_type,
     6151                ) );
     6152
     6153                array_map( 'wp_restore_post_parent', $children );
     6154        } else if ( 'publish' === $old_status && 'publish' !== $new_status ) {
     6155                $children = get_posts( array(
     6156                        'fields'      => 'ids',
     6157                        'post_parent' => $post->ID,
     6158                        'post_status' => 'any',
     6159                        'post_type'   => $post->post_type,
     6160                ) );
     6161
     6162                array_map( 'wp_remove_post_parent', $children );
     6163        }
     6164}