Make WordPress Core


Ignore:
Timestamp:
10/03/2017 03:43:01 AM (7 years ago)
Author:
westonruter
Message:

Customize: Provide validation feedback for invalid Custom Link URLs in nav menu items.

Props RMarks, EGregor, umangvaghela123, andrew.taylor, celloexpressions, westonruter, voldemortensen.
Fixes #32816.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php

    r41162 r41697  
    642642     *
    643643     * @param array $menu_item_value The value to sanitize.
    644      * @return array|false|null Null if an input isn't valid. False if it is marked for deletion.
    645      *                          Otherwise the sanitized value.
     644     * @return array|false|null|WP_Error Null or WP_Error if an input isn't valid. False if it is marked for deletion.
     645     *                                   Otherwise the sanitized value.
    646646     */
    647647    public function sanitize( $menu_item_value ) {
     
    702702        $menu_item_value['description'] = wp_unslash( apply_filters( 'content_save_pre', wp_slash( $menu_item_value['description'] ) ) );
    703703
    704         $menu_item_value['url'] = esc_url_raw( $menu_item_value['url'] );
     704        if ( '' !== $menu_item_value['url'] ) {
     705            $menu_item_value['url'] = esc_url_raw( $menu_item_value['url'] );
     706            if ( '' === $menu_item_value['url'] ) {
     707                return new WP_Error( 'invalid_url', __( 'Invalid URL.' ) ); // Fail sanitization if URL is invalid.
     708            }
     709        }
    705710        if ( 'publish' !== $menu_item_value['status'] ) {
    706711            $menu_item_value['status'] = 'draft';
Note: See TracChangeset for help on using the changeset viewer.