Make WordPress Core


Ignore:
Timestamp:
09/30/2025 05:04:35 PM (11 months ago)
Author:
desrosj
Message:

Grouped backports for the 5.4 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 5.4 branch.

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

Location:
branches/5.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.4

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

    r47383 r60832  
    5757                'xfn'              => '',
    5858                'status'           => 'publish',
    59                 'original_title'   => '',
    6059                'nav_menu_term_id' => 0, // This will be supplied as the $menu_id arg for wp_update_nav_menu_item().
    6160                '_invalid'         => false,
     
    212211         */
    213212        public function value() {
     213                $type_label = null;
    214214                if ( $this->is_previewed && get_current_blog_id() === $this->_previewed_blog_id ) {
    215215                        $undefined  = new stdClass(); // Symbol.
     
    220220                        } else {
    221221                                $value = $post_value;
    222                         }
    223                         if ( ! empty( $value ) && empty( $value['original_title'] ) ) {
    224                                 $value['original_title'] = $this->get_original_title( (object) $value );
    225222                        }
    226223                } elseif ( isset( $this->value ) ) {
     
    235232                                        $is_title_empty = empty( $post->post_title );
    236233                                        $value          = (array) wp_setup_nav_menu_item( $post );
     234                                        if ( isset( $value['type_label'] ) ) {
     235                                                $type_label = $value['type_label'];
     236                                        }
    237237                                        if ( $is_title_empty ) {
    238238                                                $value['title'] = '';
     
    251251                }
    252252
    253                 if ( ! empty( $value ) && empty( $value['type_label'] ) ) {
    254                         $value['type_label'] = $this->get_type_label( (object) $value );
     253                // These properties are read-only and are part of the setting for use in the Customizer UI.
     254                if ( is_array( $value ) ) {
     255                        $value_obj               = (object) $value;
     256                        $value['type_label']     = isset( $type_label ) ? $type_label : $this->get_type_label( $value_obj );
     257                        $value['original_title'] = $this->get_original_title( $value_obj );
    255258                }
    256259
     
    259262
    260263        /**
     264         * Prepares the value for editing on the client.
     265         *
     266         * @since 6.8.3
     267         *
     268         * @return array|false Value prepared for the client.
     269         */
     270        public function js_value() {
     271                $value = parent::js_value();
     272                if ( is_array( $value ) && isset( $value['original_title'] ) ) {
     273                        // Decode entities for the sake of displaying the original title as a placeholder.
     274                        $value['original_title'] = html_entity_decode( $value['original_title'], ENT_QUOTES, get_bloginfo( 'charset' ) );
     275                }
     276                return $value;
     277        }
     278
     279        /**
    261280         * Get original title.
    262281         *
     
    264283         *
    265284         * @param object $item Nav menu item.
    266          * @return string The original title.
     285         * @return string The original title, without entity decoding.
    267286         */
    268287        protected function get_original_title( $item ) {
     
    290309                        }
    291310                }
    292                 $original_title = html_entity_decode( $original_title, ENT_QUOTES, get_bloginfo( 'charset' ) );
    293311                return $original_title;
    294312        }
     
    346364                        $this->value['status'] = $this->value['post_status'];
    347365                        unset( $this->value['post_status'] );
    348                 }
    349 
    350                 if ( ! isset( $this->value['original_title'] ) ) {
    351                         $this->value['original_title'] = $this->get_original_title( (object) $this->value );
    352366                }
    353367
     
    596610                unset( $item->position );
    597611
    598                 if ( empty( $item->original_title ) ) {
    599                         $item->original_title = $this->get_original_title( $item );
    600                 }
    601612                if ( empty( $item->title ) && ! empty( $item->original_title ) ) {
    602                         $item->title = $item->original_title;
     613                        $item->title = $item->original_title; // This is NOT entity-decoded. It comes from self::get_original_title().
    603614                }
    604615                if ( $item->title ) {
     
    650661         * @since 4.3.0
    651662         *
    652          * @param array $menu_item_value The value to sanitize.
     663         * @param array|false $value The menu item value to sanitize.
    653664         * @return array|false|null|WP_Error Null or WP_Error if an input isn't valid. False if it is marked for deletion.
    654665         *                                   Otherwise the sanitized value.
     
    704715                }
    705716
    706                 $menu_item_value['original_title'] = sanitize_text_field( $menu_item_value['original_title'] );
    707 
    708717                // Apply the same filters as when calling wp_insert_post().
    709718
Note: See TracChangeset for help on using the changeset viewer.