Make WordPress Core


Ignore:
Timestamp:
06/19/2016 12:01:11 PM (8 years ago)
Author:
swissspidy
Message:

Permalinks: Validate custom permalink structures.

Custom permalink structures require at least one valid structure tag, e.g. %postname%. If none is included, it would leave users with broken permalinks.
Let's make sure this won't happen by validating the permalink structure.

Adds unit tests.

Props rockwell15 for initial patch.
Fixes #35936.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/options-permalink.php

    r36142 r37747  
    8383                $permalink_structure = $blog_prefix . $permalink_structure;
    8484        }
     85
     86        $permalink_structure = sanitize_option( 'permalink_structure', $permalink_structure );
     87
    8588        $wp_rewrite->set_permalink_structure( $permalink_structure );
    8689    }
     
    99102        $wp_rewrite->set_tag_base( $tag_base );
    100103    }
     104
     105    $message = __( 'Permalink structure updated.' );
     106
     107    if ( $iis7_permalinks ) {
     108        if ( $permalink_structure && ! $usingpi && ! $writable ) {
     109            $message = __( 'You should update your web.config now.' );
     110        } elseif ( $permalink_structure && ! $usingpi && $writable ) {
     111            $message = __( 'Permalink structure updated. Remove write access on web.config file now!' );
     112        }
     113    } elseif ( ! $is_nginx && $permalink_structure && ! $usingpi && ! $writable && $update_required ) {
     114        $message = __( 'You should update your .htaccess now.' );
     115    }
     116
     117    if ( ! get_settings_errors() ) {
     118        add_settings_error( 'general', 'settings_updated', $message, 'updated' );
     119    }
     120
     121    set_transient( 'settings_errors', get_settings_errors(), 30 );
    101122
    102123    wp_redirect( admin_url( 'options-permalink.php?settings-updated=true' ) );
     
    126147}
    127148
    128 if ( $wp_rewrite->using_index_permalinks() )
    129     $usingpi = true;
    130 else
    131     $usingpi = false;
     149$usingpi = $wp_rewrite->using_index_permalinks();
    132150
    133151flush_rewrite_rules();
    134152
    135153require( ABSPATH . 'wp-admin/admin-header.php' );
    136 
    137 if ( ! empty( $_GET['settings-updated'] ) ) : ?>
    138 <div id="message" class="updated notice is-dismissible"><p><?php
    139 if ( ! is_multisite() ) {
    140     if ( $iis7_permalinks ) {
    141         if ( $permalink_structure && ! $usingpi && ! $writable ) {
    142             _e('You should update your web.config now.');
    143         } elseif ( $permalink_structure && ! $usingpi && $writable ) {
    144             _e('Permalink structure updated. Remove write access on web.config file now!');
    145         } else {
    146             _e('Permalink structure updated.');
    147         }
    148     } elseif ( $is_nginx ) {
    149         _e('Permalink structure updated.');
    150     } else {
    151         if ( $permalink_structure && ! $usingpi && ! $writable && $update_required ) {
    152             _e('You should update your .htaccess now.');
    153         } else {
    154             _e('Permalink structure updated.');
    155         }
    156     }
    157 } else {
    158     _e('Permalink structure updated.');
    159 }
    160154?>
    161 </p></div>
    162 <?php endif; ?>
    163 
    164155<div class="wrap">
    165156<h1><?php echo esc_html( $title ); ?></h1>
Note: See TracChangeset for help on using the changeset viewer.