Make WordPress Core

Changeset 38066


Ignore:
Timestamp:
07/16/2016 12:43:16 PM (8 years ago)
Author:
SergeyBiryukov
Message:

Permalinks: After [37747], make sure $usingpi, $writable, and $update_required are defined before checking them on permalinks update.

Props Clorith.
Fixes #37380.

File:
1 edited

Legend:

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

    r37914 r38066  
    6565if ( is_multisite() && ! is_subdomain_install() && is_main_site() && 0 === strpos( $permalink_structure, '/blog/' ) ) {
    6666    $blog_prefix = '/blog';
    67 }
    68 
    69 if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
    70     check_admin_referer('update-permalink');
    71 
    72     if ( isset( $_POST['permalink_structure'] ) ) {
    73         if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] )
    74             $permalink_structure = $_POST['selection'];
    75         else
    76             $permalink_structure = $_POST['permalink_structure'];
    77 
    78         if ( ! empty( $permalink_structure ) ) {
    79             $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) );
    80             if ( $prefix && $blog_prefix )
    81                 $permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure );
    82             else
    83                 $permalink_structure = $blog_prefix . $permalink_structure;
    84         }
    85 
    86         $permalink_structure = sanitize_option( 'permalink_structure', $permalink_structure );
    87 
    88         $wp_rewrite->set_permalink_structure( $permalink_structure );
    89     }
    90 
    91     if ( isset( $_POST['category_base'] ) ) {
    92         $category_base = $_POST['category_base'];
    93         if ( ! empty( $category_base ) )
    94             $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
    95         $wp_rewrite->set_category_base( $category_base );
    96     }
    97 
    98     if ( isset( $_POST['tag_base'] ) ) {
    99         $tag_base = $_POST['tag_base'];
    100         if ( ! empty( $tag_base ) )
    101             $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
    102         $wp_rewrite->set_tag_base( $tag_base );
    103     }
    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 );
    122 
    123     wp_redirect( admin_url( 'options-permalink.php?settings-updated=true' ) );
    124     exit;
    12567}
    12668
     
    14991$usingpi = $wp_rewrite->using_index_permalinks();
    15092
     93if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
     94    check_admin_referer('update-permalink');
     95
     96    if ( isset( $_POST['permalink_structure'] ) ) {
     97        if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] )
     98            $permalink_structure = $_POST['selection'];
     99        else
     100            $permalink_structure = $_POST['permalink_structure'];
     101
     102        if ( ! empty( $permalink_structure ) ) {
     103            $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) );
     104            if ( $prefix && $blog_prefix )
     105                $permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure );
     106            else
     107                $permalink_structure = $blog_prefix . $permalink_structure;
     108        }
     109
     110        $permalink_structure = sanitize_option( 'permalink_structure', $permalink_structure );
     111
     112        $wp_rewrite->set_permalink_structure( $permalink_structure );
     113    }
     114
     115    if ( isset( $_POST['category_base'] ) ) {
     116        $category_base = $_POST['category_base'];
     117        if ( ! empty( $category_base ) )
     118            $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
     119        $wp_rewrite->set_category_base( $category_base );
     120    }
     121
     122    if ( isset( $_POST['tag_base'] ) ) {
     123        $tag_base = $_POST['tag_base'];
     124        if ( ! empty( $tag_base ) )
     125            $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
     126        $wp_rewrite->set_tag_base( $tag_base );
     127    }
     128
     129    $message = __( 'Permalink structure updated.' );
     130
     131    if ( $iis7_permalinks ) {
     132        if ( $permalink_structure && ! $usingpi && ! $writable ) {
     133            $message = __( 'You should update your web.config now.' );
     134        } elseif ( $permalink_structure && ! $usingpi && $writable ) {
     135            $message = __( 'Permalink structure updated. Remove write access on web.config file now!' );
     136        }
     137    } elseif ( ! $is_nginx && $permalink_structure && ! $usingpi && ! $writable && $update_required ) {
     138        $message = __( 'You should update your .htaccess now.' );
     139    }
     140
     141    if ( ! get_settings_errors() ) {
     142        add_settings_error( 'general', 'settings_updated', $message, 'updated' );
     143    }
     144
     145    set_transient( 'settings_errors', get_settings_errors(), 30 );
     146
     147    wp_redirect( admin_url( 'options-permalink.php?settings-updated=true' ) );
     148    exit;
     149}
     150
    151151flush_rewrite_rules();
    152152
Note: See TracChangeset for help on using the changeset viewer.