Make WordPress Core

Ticket #40527: 40527.2.diff

File 40527.2.diff, 22.6 KB (added by dlh, 7 years ago)
  • src/wp-includes/class-wp-customize-changeset.php

     
     1<?php
     2/**
     3 * Class file for WP_Customize_Changeset
     4 *
     5 * @package WordPress
     6 * @subpackage Customize
     7 * @since 4.9.0
     8 */
     9
     10/**
     11 * Representation of a Customize Changeset.
     12 */
     13class WP_Customize_Changeset {
     14        /**
     15         * Changeset UUID, the post_name for the customize_changeset post containing the customized state.
     16         *
     17         * @since 4.9.0
     18         * @var string
     19         */
     20        protected $uuid;
     21
     22        /**
     23         * Changeset post ID.
     24         *
     25         * @since 4.9.0
     26         * @var int
     27         */
     28        protected $post_id;
     29
     30        /**
     31         * Retrieve a WP_Customize_Changeset instance from a changeset UUID.
     32         *
     33         * Defers to {@see WP_Customize_Changeset::from_post()} if a post for the UUID exists.
     34         *
     35         * @since 4.9.0
     36         *
     37         * @param string $uuid UUID.
     38         * @return WP_Customize_Changeset Changeset instance.
     39         */
     40        public static function from_uuid( $uuid ) {
     41                $cache_group = 'customize_changeset_post';
     42
     43                $post_id = wp_cache_get( $uuid, $cache_group );
     44
     45                if ( $post_id && 'customize_changeset' === get_post_type( $post_id ) ) {
     46                        return WP_Customize_Changeset::from_post( $post_id );
     47                }
     48
     49                // The full post object is being retrieved so it's cached.
     50                $query = new WP_Query( array(
     51                        'post_type' => 'customize_changeset',
     52                        'post_status' => get_post_stati(),
     53                        'name' => $uuid,
     54                        'posts_per_page' => 1,
     55                        'no_found_rows' => true,
     56                        'cache_results' => true,
     57                        'update_post_meta_cache' => false,
     58                        'update_post_term_cache' => false,
     59                        'lazy_load_term_meta' => false,
     60                ) );
     61
     62                if ( empty( $query->posts ) ) {
     63                        $instance = new WP_Customize_Changeset();
     64                        $instance->set_uuid( $uuid );
     65                        return $instance;
     66                }
     67
     68                $post_id = $query->posts[0]->ID;
     69                wp_cache_set( $uuid, $post_id, $cache_group );
     70
     71                return WP_Customize_Changeset::from_post( $post_id );
     72        }
     73
     74        /**
     75         * Retrieve a WP_Customize_Changeset instance from a post.
     76         *
     77         * @since 4.9.0
     78         *
     79         * @param int|WP_Post $post Post ID or object.
     80         * @return WP_Customize_Changeset|null Changeset instance or failure return value from {@see get_post()}.
     81         */
     82        public static function from_post( $post ) {
     83                $post = get_post( $post );
     84
     85                if ( ! ( $post instanceof WP_Post ) ) {
     86                        return $post;
     87                }
     88
     89                $instance = new WP_Customize_Changeset();
     90                $instance->parse_post( $post );
     91                return $instance;
     92        }
     93
     94        /**
     95         * Populate instance properties from a post object.
     96         *
     97         * @since 4.9.0
     98         *
     99         * @param WP_Post $post Post object.
     100         */
     101        public function parse_post( $post ) {
     102                $this->post_id = $post->ID;
     103                $this->uuid = $post->post_name;
     104        }
     105
     106        /**
     107         * Set the instance UUID.
     108         *
     109         * @param string $uuid UUID.
     110         */
     111        public function set_uuid( $uuid ) {
     112                $this->uuid = $uuid;
     113        }
     114
     115        /**
     116         * Get the changeset UUID.
     117         *
     118         * @since 4.9.0
     119         *
     120         * @return string UUID.
     121         */
     122        public function get_uuid() {
     123                return $this->uuid;
     124        }
     125
     126        /**
     127         * Get the changeset post ID.
     128         *
     129         * @return int
     130         */
     131        public function get_post_id() {
     132                return $this->post_id;
     133        }
     134
     135        /**
     136         * Get the data stored in the changeset post, if one exists.
     137         *
     138         * @since 4.9.0
     139         *
     140         * @return array|WP_Error Changeset data or WP_Error on error.
     141         */
     142        public function get_post_data() {
     143                if ( ! $this->post_id ) {
     144                        return new WP_Error( 'empty_post_id' );
     145                }
     146
     147                $post = get_post( $this->post_id );
     148
     149                if ( ! $post ) {
     150                        return new WP_Error( 'missing_post' );
     151                }
     152
     153                if ( 'customize_changeset' !== get_post_type( $post ) ) {
     154                        return new WP_Error( 'wrong_post_type' );
     155                }
     156
     157                $data = json_decode( $post->post_content, true );
     158
     159                if ( function_exists( 'json_last_error' ) ) {
     160                        $error = json_last_error();
     161
     162                        if ( $error ) {
     163                                return new WP_Error( 'json_parse_error', '', $error );
     164                        }
     165                }
     166
     167                if ( ! is_array( $data ) ) {
     168                        return new WP_Error( 'expected_array' );
     169                }
     170
     171                return $data;
     172        }
     173
     174        /**
     175         * Get the changeset data.
     176         *
     177         * @since 4.9.0
     178         *
     179         * @return array Changeset data.
     180         */
     181        public function get_data() {
     182                $data = $this->get_post_data();
     183                return ( is_wp_error( $data ) ) ? array() : $data;
     184        }
     185
     186        /**
     187         * Save the changeset post.
     188         *
     189         * @since 4.9.0
     190         *
     191         * @param array $args {
     192         *     Array of arguments that make up the changeset.
     193         *
     194         *     @type array  $data     Changeset data.
     195         *     @type string $date_gmt Changeset date in GMT. Optional.
     196         *     @type string $status   Changeset status. Optional.
     197         *     @type string $title    Changeset title. Optional.
     198         * }
     199         * @return int|WP_Error Changeset post ID on success or WP_Error.
     200         */
     201        public function save( $args ) {
     202                $args = wp_parse_args( $args, array(
     203                        'data' => array(),
     204                        'date_gmt' => null,
     205                        'status' => null,
     206                        'title' => null,
     207                ) );
     208
     209                $json_options = 0;
     210
     211                if ( defined( 'JSON_UNESCAPED_SLASHES' ) ) {
     212                        // Introduced in PHP 5.4. This is only to improve readability as slashes needn't be escaped in storage.
     213                        $json_options |= JSON_UNESCAPED_SLASHES;
     214                }
     215
     216                // Also introduced in PHP 5.4, but WP defines constant for back compat. See WP Trac #30139.
     217                $json_options |= JSON_PRETTY_PRINT;
     218
     219                $post_array = array(
     220                        'post_content' => wp_json_encode( $args['data'], $json_options ),
     221                );
     222
     223                if ( $args['title'] ) {
     224                        $post_array['post_title'] = $args['title'];
     225                }
     226
     227                // @todo What if there is no UUID or post ID?
     228                if ( $this->post_id ) {
     229                        $post_array['ID'] = $this->post_id;
     230                } else {
     231                        $post_array['post_type'] = 'customize_changeset';
     232                        $post_array['post_name'] = $this->uuid;
     233                        $post_array['post_status'] = 'auto-draft';
     234                }
     235
     236                if ( $args['status'] ) {
     237                        $post_array['post_status'] = $args['status'];
     238                }
     239
     240                // Reset post date to now if we are publishing, otherwise pass post_date_gmt and translate for post_date.
     241                if ( 'publish' === $args['status'] ) {
     242                        $post_array['post_date_gmt'] = '0000-00-00 00:00:00';
     243                        $post_array['post_date'] = '0000-00-00 00:00:00';
     244                } elseif ( $args['date_gmt'] ) {
     245                        $post_array['post_date_gmt'] = $args['date_gmt'];
     246                        $post_array['post_date'] = get_date_from_gmt( $args['date_gmt'] );
     247                } elseif ( $this->post_id && 'auto-draft' === get_post_status( $this->post_id ) ) {
     248                        /*
     249                         * Keep bumping the date for the auto-draft whenever it is modified;
     250                         * this extends its life, preserving it from garbage-collection via
     251                         * wp_delete_auto_drafts().
     252                         */
     253                        $post_array['post_date'] = current_time( 'mysql' );
     254                        $post_array['post_date_gmt'] = '';
     255                }
     256
     257                /*
     258                 * Update the changeset post. The 'publish_customize_changeset' action
     259                 * will cause the settings in the changeset to be saved via
     260                 * WP_Customize_Setting::save().
     261                 */
     262                $has_kses = ( false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ) );
     263                if ( $has_kses ) {
     264                        // Prevent KSES from corrupting JSON in post_content.
     265                        kses_remove_filters();
     266                }
     267
     268                // Note that updating a post with publish status will trigger WP_Customize_Manager::publish_changeset_values().
     269                if ( $this->post_id ) {
     270                        // Prevent date clearing.
     271                        $post_array['edit_date'] = true;
     272
     273                        $result = wp_update_post( wp_slash( $post_array ), true );
     274                } else {
     275                        $result = wp_insert_post( wp_slash( $post_array ), true );
     276
     277                        if ( is_numeric( $result ) ) {
     278                                $this->post_id = (int) $result;
     279                        }
     280                }
     281
     282                if ( $has_kses ) {
     283                        kses_init_filters();
     284                }
     285
     286                return $result;
     287        }
     288
     289        /**
     290         * Publish the changeset values.
     291         *
     292         * @since 4.9.0
     293         *
     294         * @param  WP_Customize_Manager $wp_customize Customize manager instance that
     295         *                                            should publish the changeset.
     296         * @return bool|WP_Error True or a WP_Error.
     297         */
     298        public function publish( $wp_customize ) {
     299                $result = $wp_customize->_publish_changeset_values( $this->post_id );
     300
     301                if ( true === $result ) {
     302                        /*
     303                         * Trash the changeset post if revisions are not enabled.
     304                         *
     305                         * Unpublished changesets by default get garbage collected due to
     306                         * their auto-draft status. When a changeset post is published,
     307                         * however, it would no longer get cleaned out. Ths is a problem
     308                         * when the changeset posts are never displayed anywhere, since they
     309                         * would just be endlessly piling up. So here we use the revisions
     310                         * feature to indicate whether or not a published changeset should
     311                         * get trashed and thus garbage collected.
     312                         */
     313                        if ( ! wp_revisions_enabled( get_post( $this->post_id ) ) ) {
     314                                $this->trash();
     315                        }
     316                }
     317
     318                return $result;
     319        }
     320
     321        /**
     322         * Trash or delete the changeset post.
     323         *
     324         * The following re-formulates the logic from wp_trash_post() as done in
     325         * wp_publish_post(). The reason for bypassing wp_trash_post() is that it
     326         * will mutate the the post_content and the post_name when they should be
     327         * untouched.
     328         *
     329         * @global wpdb $wpdb WordPress database abstraction object.
     330         *
     331         * @return mixed The trashed post as an array or an empty value on failure.
     332         */
     333        public function trash() {
     334                global $wpdb;
     335
     336                if ( ! EMPTY_TRASH_DAYS ) {
     337                        return wp_delete_post( (int) $this->post_id, true );
     338                }
     339
     340                if ( $this->post_id ) {
     341                        $post = get_post( $this->post_id );
     342                }
     343
     344
     345                if ( empty( $post ) ) {
     346                        return $post;
     347                }
     348
     349                if ( get_post_status( $post ) === 'trash' ) {
     350                        return false;
     351                }
     352
     353                $post_id = $post->ID;
     354
     355                /** This action is documented in wp-includes/post.php */
     356                do_action( 'wp_trash_post', $post_id );
     357
     358                add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status );
     359                add_post_meta( $post_id, '_wp_trash_meta_time', time() );
     360
     361                $old_status = $post->post_status;
     362                $new_status = 'trash';
     363                $wpdb->update( $wpdb->posts, array( 'post_status' => $new_status ), array( 'ID' => $post->ID ) );
     364                clean_post_cache( $post->ID );
     365
     366                $post->post_status = $new_status;
     367                wp_transition_post_status( $new_status, $old_status, $post );
     368
     369                /** This action is documented in wp-includes/post.php */
     370                do_action( 'edit_post', $post->ID, $post );
     371
     372                /** This action is documented in wp-includes/post.php */
     373                do_action( "save_post_{$post->post_type}", $post->ID, $post, true );
     374
     375                /** This action is documented in wp-includes/post.php */
     376                do_action( 'save_post', $post->ID, $post, true );
     377
     378                /** This action is documented in wp-includes/post.php */
     379                do_action( 'wp_insert_post', $post->ID, $post, true );
     380
     381                wp_trash_post_comments( $post_id );
     382
     383                /** This action is documented in wp-includes/post.php */
     384                do_action( 'trashed_post', $post_id );
     385
     386                return $post->to_array();
     387        }
     388}
  • src/wp-includes/class-wp-customize-manager.php

     
    205205        private $_changeset_post_id;
    206206
    207207        /**
    208          * Changeset data loaded from a customize_changeset post.
    209          *
    210          * @since 4.7.0
    211          * @var array
    212          */
    213         private $_changeset_data;
    214 
    215         /**
    216208         * Constructor.
    217209         *
    218210         * @since 3.4.0
     
    796788         * @return int|null Returns post ID on success and null on failure.
    797789         */
    798790        public function find_changeset_post_id( $uuid ) {
    799                 $cache_group = 'customize_changeset_post';
    800                 $changeset_post_id = wp_cache_get( $uuid, $cache_group );
    801                 if ( $changeset_post_id && 'customize_changeset' === get_post_type( $changeset_post_id ) ) {
    802                         return $changeset_post_id;
    803                 }
    804 
    805                 $changeset_post_query = new WP_Query( array(
    806                         'post_type' => 'customize_changeset',
    807                         'post_status' => get_post_stati(),
    808                         'name' => $uuid,
    809                         'posts_per_page' => 1,
    810                         'no_found_rows' => true,
    811                         'cache_results' => true,
    812                         'update_post_meta_cache' => false,
    813                         'update_post_term_cache' => false,
    814                         'lazy_load_term_meta' => false,
    815                 ) );
    816                 if ( ! empty( $changeset_post_query->posts ) ) {
    817                         // Note: 'fields'=>'ids' is not being used in order to cache the post object as it will be needed.
    818                         $changeset_post_id = $changeset_post_query->posts[0]->ID;
    819                         wp_cache_set( $this->_changeset_uuid, $changeset_post_id, $cache_group );
    820                         return $changeset_post_id;
    821                 }
    822 
    823                 return null;
     791                $changeset = WP_Customize_Changeset::from_uuid( $uuid );
     792                return $changeset->get_post_id();
    824793        }
    825794
    826795        /**
     
    853822         * @return array|WP_Error Changeset data or WP_Error on error.
    854823         */
    855824        protected function get_changeset_post_data( $post_id ) {
    856                 if ( ! $post_id ) {
    857                         return new WP_Error( 'empty_post_id' );
    858                 }
    859                 $changeset_post = get_post( $post_id );
    860                 if ( ! $changeset_post ) {
     825                $changeset = WP_Customize_Changeset::from_post( $post_id );
     826
     827                if ( ! ( $changeset instanceof WP_Customize_Changeset ) ) {
     828                        // This error code is also used in WP_Customize_Changeset::parse_post().
    861829                        return new WP_Error( 'missing_post' );
    862830                }
    863                 if ( 'customize_changeset' !== $changeset_post->post_type ) {
    864                         return new WP_Error( 'wrong_post_type' );
    865                 }
    866                 $changeset_data = json_decode( $changeset_post->post_content, true );
    867                 if ( function_exists( 'json_last_error' ) && json_last_error() ) {
    868                         return new WP_Error( 'json_parse_error', '', json_last_error() );
    869                 }
    870                 if ( ! is_array( $changeset_data ) ) {
    871                         return new WP_Error( 'expected_array' );
    872                 }
    873                 return $changeset_data;
     831
     832                return $changeset->get_post_data();
    874833        }
    875834
    876835        /**
     
    881840         * @return array Changeset data.
    882841         */
    883842        public function changeset_data() {
    884                 if ( isset( $this->_changeset_data ) ) {
    885                         return $this->_changeset_data;
    886                 }
    887843                $changeset_post_id = $this->changeset_post_id();
     844
    888845                if ( ! $changeset_post_id ) {
    889                         $this->_changeset_data = array();
     846                        $data = array();
    890847                } else {
    891848                        $data = $this->get_changeset_post_data( $changeset_post_id );
    892                         if ( ! is_wp_error( $data ) ) {
    893                                 $this->_changeset_data = $data;
    894                         } else {
    895                                 $this->_changeset_data = array();
     849
     850                        if ( is_wp_error( $data ) ) {
     851                                $data = array();
    896852                        }
    897853                }
    898                 return $this->_changeset_data;
     854
     855                return $data;
    899856        }
    900857
    901858        /**
     
    22302187                );
    22312188
    22322189                $changeset_post_id = $this->changeset_post_id();
     2190                $changeset = WP_Customize_Changeset::from_post( $changeset_post_id );
     2191
     2192                if ( ! ( $changeset instanceof WP_Customize_Changeset ) ) {
     2193                        $changeset = WP_Customize_Changeset::from_uuid( $this->changeset_uuid() );
     2194                }
     2195
    22332196                $existing_changeset_data = array();
    22342197                if ( $changeset_post_id ) {
    22352198                        $existing_status = get_post_status( $changeset_post_id );
     
    24622425                        $this->start_previewing_theme();
    24632426                }
    24642427
    2465                 // Gather the data for wp_insert_post()/wp_update_post().
    2466                 $json_options = 0;
    2467                 if ( defined( 'JSON_UNESCAPED_SLASHES' ) ) {
    2468                         $json_options |= JSON_UNESCAPED_SLASHES; // Introduced in PHP 5.4. This is only to improve readability as slashes needn't be escaped in storage.
    2469                 }
    2470                 $json_options |= JSON_PRETTY_PRINT; // Also introduced in PHP 5.4, but WP defines constant for back compat. See WP Trac #30139.
    2471                 $post_array = array(
    2472                         'post_content' => wp_json_encode( $data, $json_options ),
    2473                 );
    2474                 if ( $args['title'] ) {
    2475                         $post_array['post_title'] = $args['title'];
    2476                 }
    2477                 if ( $changeset_post_id ) {
    2478                         $post_array['ID'] = $changeset_post_id;
    2479                 } else {
    2480                         $post_array['post_type'] = 'customize_changeset';
    2481                         $post_array['post_name'] = $this->changeset_uuid();
    2482                         $post_array['post_status'] = 'auto-draft';
    2483                 }
    2484                 if ( $args['status'] ) {
    2485                         $post_array['post_status'] = $args['status'];
    2486                 }
    2487 
    2488                 // Reset post date to now if we are publishing, otherwise pass post_date_gmt and translate for post_date.
    2489                 if ( 'publish' === $args['status'] ) {
    2490                         $post_array['post_date_gmt'] = '0000-00-00 00:00:00';
    2491                         $post_array['post_date'] = '0000-00-00 00:00:00';
    2492                 } elseif ( $args['date_gmt'] ) {
    2493                         $post_array['post_date_gmt'] = $args['date_gmt'];
    2494                         $post_array['post_date'] = get_date_from_gmt( $args['date_gmt'] );
    2495                 } elseif ( $changeset_post_id && 'auto-draft' === get_post_status( $changeset_post_id ) ) {
    2496                         /*
    2497                          * Keep bumping the date for the auto-draft whenever it is modified;
    2498                          * this extends its life, preserving it from garbage-collection via
    2499                          * wp_delete_auto_drafts().
    2500                          */
    2501                         $post_array['post_date'] = current_time( 'mysql' );
    2502                         $post_array['post_date_gmt'] = '';
    2503                 }
    2504 
    25052428                $this->store_changeset_revision = $allow_revision;
    25062429                add_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ), 5, 3 );
    25072430
    2508                 // Update the changeset post. The publish_customize_changeset action will cause the settings in the changeset to be saved via WP_Customize_Setting::save().
    2509                 $has_kses = ( false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ) );
    2510                 if ( $has_kses ) {
    2511                         kses_remove_filters(); // Prevent KSES from corrupting JSON in post_content.
    2512                 }
     2431                $r = $changeset->save( array(
     2432                        'data' => $data,
     2433                        'date_gmt' => $args['date_gmt'],
     2434                        'status' => $args['status'],
     2435                        'title' => $args['title'],
     2436                ) );
    25132437
    2514                 // Note that updating a post with publish status will trigger WP_Customize_Manager::publish_changeset_values().
    2515                 if ( $changeset_post_id ) {
    2516                         $post_array['edit_date'] = true; // Prevent date clearing.
    2517                         $r = wp_update_post( wp_slash( $post_array ), true );
    2518                 } else {
    2519                         $r = wp_insert_post( wp_slash( $post_array ), true );
    2520                         if ( ! is_wp_error( $r ) ) {
    2521                                 $this->_changeset_post_id = $r; // Update cached post ID for the loaded changeset.
    2522                         }
     2438                if ( ! is_wp_error( $r ) ) {
     2439                        $this->_changeset_post_id = $r; // Update cached post ID for the loaded changeset.
    25232440                }
    2524                 if ( $has_kses ) {
    2525                         kses_init_filters();
    2526                 }
    2527                 $this->_changeset_data = null; // Reset so WP_Customize_Manager::changeset_data() will re-populate with updated contents.
    25282441
    25292442                remove_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ) );
    25302443
     
    26052518                $this->_changeset_post_id   = $changeset_post_id;
    26062519                $previous_changeset_uuid    = $this->_changeset_uuid;
    26072520                $this->_changeset_uuid      = $changeset_post->post_name;
    2608                 $previous_changeset_data    = $this->_changeset_data;
    2609                 $this->_changeset_data      = $publishing_changeset_data;
    26102521
    26112522                // Parse changeset data to identify theme mod settings and user IDs associated with settings to be saved.
    26122523                $setting_user_ids = array();
     
    26132524                $theme_mod_settings = array();
    26142525                $namespace_pattern = '/^(?P<stylesheet>.+?)::(?P<setting_id>.+)$/';
    26152526                $matches = array();
    2616                 foreach ( $this->_changeset_data as $raw_setting_id => $setting_params ) {
     2527                foreach ( $this->changeset_data() as $raw_setting_id => $setting_params ) {
    26172528                        $actual_setting_id = null;
    26182529                        $is_theme_mod_setting = (
    26192530                                isset( $setting_params['value'] )
     
    27222633                }
    27232634
    27242635                // Restore original changeset data.
    2725                 $this->_changeset_data    = $previous_changeset_data;
    27262636                $this->_changeset_post_id = $previous_changeset_post_id;
    27272637                $this->_changeset_uuid    = $previous_changeset_uuid;
    27282638
  • src/wp-includes/theme.php

     
    28362836 * @since 4.7.0
    28372837 * @access private
    28382838 *
    2839  * @global wpdb                 $wpdb         WordPress database abstraction object.
    28402839 * @global WP_Customize_Manager $wp_customize Customizer instance.
    28412840 *
    28422841 * @param string  $new_status     New post status.
     
    28442843 * @param WP_Post $changeset_post Changeset post object.
    28452844 */
    28462845function _wp_customize_publish_changeset( $new_status, $old_status, $changeset_post ) {
    2847         global $wp_customize, $wpdb;
     2846        global $wp_customize;
    28482847
    28492848        $is_publishing_changeset = (
    28502849                'customize_changeset' === $changeset_post->post_type
     
    28572856                return;
    28582857        }
    28592858
     2859        $changeset = WP_Customize_Changeset::from_post( $changeset_post );
     2860
     2861        if ( ! $changeset ) {
     2862                return;
     2863        }
     2864
    28602865        if ( empty( $wp_customize ) ) {
    28612866                require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    28622867                $wp_customize = new WP_Customize_Manager( array(
     
    28862891                /** This filter is documented in /wp-includes/class-wp-customize-manager.php */
    28872892                do_action( 'customize_register', $wp_customize );
    28882893        }
    2889         $wp_customize->_publish_changeset_values( $changeset_post->ID ) ;
    28902894
    2891         /*
    2892          * Trash the changeset post if revisions are not enabled. Unpublished
    2893          * changesets by default get garbage collected due to the auto-draft status.
    2894          * When a changeset post is published, however, it would no longer get cleaned
    2895          * out. Ths is a problem when the changeset posts are never displayed anywhere,
    2896          * since they would just be endlessly piling up. So here we use the revisions
    2897          * feature to indicate whether or not a published changeset should get trashed
    2898          * and thus garbage collected.
    2899          */
    2900         if ( ! wp_revisions_enabled( $changeset_post ) ) {
    2901                 $post = $changeset_post;
    2902                 $post_id = $changeset_post->ID;
    2903 
    2904                 /*
    2905                  * The following re-formulates the logic from wp_trash_post() as done in
    2906                  * wp_publish_post(). The reason for bypassing wp_trash_post() is that it
    2907                  * will mutate the the post_content and the post_name when they should be
    2908                  * untouched.
    2909                  */
    2910                 if ( ! EMPTY_TRASH_DAYS ) {
    2911                         wp_delete_post( $post_id, true );
    2912                 } else {
    2913                         /** This action is documented in wp-includes/post.php */
    2914                         do_action( 'wp_trash_post', $post_id );
    2915 
    2916                         add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status );
    2917                         add_post_meta( $post_id, '_wp_trash_meta_time', time() );
    2918 
    2919                         $old_status = $post->post_status;
    2920                         $new_status = 'trash';
    2921                         $wpdb->update( $wpdb->posts, array( 'post_status' => $new_status ), array( 'ID' => $post->ID ) );
    2922                         clean_post_cache( $post->ID );
    2923 
    2924                         $post->post_status = $new_status;
    2925                         wp_transition_post_status( $new_status, $old_status, $post );
    2926 
    2927                         /** This action is documented in wp-includes/post.php */
    2928                         do_action( 'edit_post', $post->ID, $post );
    2929 
    2930                         /** This action is documented in wp-includes/post.php */
    2931                         do_action( "save_post_{$post->post_type}", $post->ID, $post, true );
    2932 
    2933                         /** This action is documented in wp-includes/post.php */
    2934                         do_action( 'save_post', $post->ID, $post, true );
    2935 
    2936                         /** This action is documented in wp-includes/post.php */
    2937                         do_action( 'wp_insert_post', $post->ID, $post, true );
    2938 
    2939                         /** This action is documented in wp-includes/post.php */
    2940                         do_action( 'trashed_post', $post_id );
    2941                 }
    2942         }
     2895        $changeset->publish( $wp_customize );
    29432896}
    29442897
    29452898/**
  • src/wp-settings.php

     
    218218require( ABSPATH . WPINC . '/class-wp-widget-factory.php' );
    219219require( ABSPATH . WPINC . '/nav-menu.php' );
    220220require( ABSPATH . WPINC . '/nav-menu-template.php' );
     221require( ABSPATH . WPINC . '/class-wp-customize-changeset.php' );
    221222require( ABSPATH . WPINC . '/admin-bar.php' );
    222223require( ABSPATH . WPINC . '/rest-api.php' );
    223224require( ABSPATH . WPINC . '/rest-api/class-wp-rest-server.php' );