Make WordPress Core


Ignore:
Timestamp:
09/30/2025 05:06:32 PM (10 months ago)
Author:
desrosj
Message:

Grouped backports for the 4.8 branch.

  • REST API: Increase the specificity of capability checks for collections when the edit context is in use.
  • Menus: Prevent HTML in menu item titles from being rendered unexpectedly.

Merges [60814], [60815], [60816] to the 4.8 branch.

Props andraganescu, desrosj, ehti, hurayraiit, iandunn, joehoyle, johnbillion, jorbin, mnelson4, noisysocks, peterwilsoncc, phillsav, rmccue, timothyblynjacobs, vortfu, westonruter , whyisjake, zieladam.

Location:
branches/4.8
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.8

  • branches/4.8/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php

    r39393 r60838  
    5959                'xfn'              => '',
    6060                'status'           => 'publish',
    61                 'original_title'   => '',
    6261                'nav_menu_term_id' => 0, // This will be supplied as the $menu_id arg for wp_update_nav_menu_item().
    6362                '_invalid'         => false,
     
    225224         */
    226225        public function value() {
    227                 if ( $this->is_previewed && $this->_previewed_blog_id === get_current_blog_id() ) {
     226                $type_label = null;
     227                if ( $this->is_previewed && get_current_blog_id() === $this->_previewed_blog_id ) {
    228228                        $undefined  = new stdClass(); // Symbol.
    229229                        $post_value = $this->post_value( $undefined );
     
    233233                        } else {
    234234                                $value = $post_value;
    235                         }
    236                         if ( ! empty( $value ) && empty( $value['original_title'] ) ) {
    237                                 $value['original_title'] = $this->get_original_title( (object) $value );
    238235                        }
    239236                } elseif ( isset( $this->value ) ) {
     
    248245                                        $is_title_empty = empty( $post->post_title );
    249246                                        $value = (array) wp_setup_nav_menu_item( $post );
     247                                        if ( isset( $value['type_label'] ) ) {
     248                                                $type_label = $value['type_label'];
     249                                        }
    250250                                        if ( $is_title_empty ) {
    251251                                                $value['title'] = '';
     
    264264                }
    265265
    266                 if ( ! empty( $value ) && empty( $value['type_label'] ) ) {
    267                         $value['type_label'] = $this->get_type_label( (object) $value );
    268                 }
    269 
     266                // These properties are read-only and are part of the setting for use in the Customizer UI.
     267                if ( is_array( $value ) ) {
     268                        $value_obj               = (object) $value;
     269                        $value['type_label']     = isset( $type_label ) ? $type_label : $this->get_type_label( $value_obj );
     270                        $value['original_title'] = $this->get_original_title( $value_obj );
     271                }
     272
     273                return $value;
     274        }
     275
     276        /**
     277         * Prepares the value for editing on the client.
     278         *
     279         * @since 6.8.3
     280         *
     281         * @return array|false Value prepared for the client.
     282         */
     283        public function js_value() {
     284                $value = parent::js_value();
     285                if ( is_array( $value ) && isset( $value['original_title'] ) ) {
     286                        // Decode entities for the sake of displaying the original title as a placeholder.
     287                        $value['original_title'] = html_entity_decode( $value['original_title'], ENT_QUOTES, get_bloginfo( 'charset' ) );
     288                }
    270289                return $value;
    271290        }
     
    278297         *
    279298         * @param object $item Nav menu item.
    280          * @return string The original title.
     299         * @return string The original title, without entity decoding.
    281300         */
    282301        protected function get_original_title( $item ) {
     
    304323                        }
    305324                }
    306                 $original_title = html_entity_decode( $original_title, ENT_QUOTES, get_bloginfo( 'charset' ) );
    307325                return $original_title;
    308326        }
     
    362380                        $this->value['status'] = $this->value['post_status'];
    363381                        unset( $this->value['post_status'] );
    364                 }
    365 
    366                 if ( ! isset( $this->value['original_title'] ) ) {
    367                         $this->value['original_title'] = $this->get_original_title( (object) $this->value );
    368382                }
    369383
     
    607621                unset( $item->position );
    608622
    609                 if ( empty( $item->original_title ) ) {
    610                         $item->original_title = $this->get_original_title( $item );
    611                 }
    612623                if ( empty( $item->title ) && ! empty( $item->original_title ) ) {
    613                         $item->title = $item->original_title;
     624                        $item->title = $item->original_title; // This is NOT entity-decoded. It comes from self::get_original_title().
    614625                }
    615626                if ( $item->title ) {
     
    662673         * @access public
    663674         *
    664          * @param array $menu_item_value The value to sanitize.
     675         * @param array|false $menu_item_value The value to sanitize.
    665676         * @return array|false|null Null if an input isn't valid. False if it is marked for deletion.
    666677         *                          Otherwise the sanitized value.
     
    716727                }
    717728
    718                 $menu_item_value['original_title'] = sanitize_text_field( $menu_item_value['original_title'] );
    719 
    720729                // Apply the same filters as when calling wp_insert_post().
    721730                $menu_item_value['title'] = wp_unslash( apply_filters( 'title_save_pre', wp_slash( $menu_item_value['title'] ) ) );
Note: See TracChangeset for help on using the changeset viewer.