Make WordPress Core

Changeset 48710


Ignore:
Timestamp:
08/02/2020 12:34:05 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Permalinks: Correct the check whether .htaccess update is required when saving permalink settings.

The check should be performed after the permalink structure update, not before.

Fixes #50834.

File:
1 edited

Legend:

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

    r48694 r48710  
    7373}
    7474
    75 /*
     75/**
    7676 * In a subdirectory configuration of multisite, the `/blog` prefix is used by
    7777 * default on the main site to avoid collisions with other sites created on that
     
    8383}
    8484
    85 $category_base   = get_option( 'category_base' );
    86 $tag_base        = get_option( 'tag_base' );
    87 $update_required = false;
    88 
    89 if ( $iis7_permalinks ) {
    90     if ( ( ! file_exists( $home_path . 'web.config' ) && win_is_writable( $home_path ) ) || win_is_writable( $home_path . 'web.config' ) ) {
    91         $writable = true;
    92     } else {
    93         $writable = false;
    94     }
    95 } elseif ( $is_nginx ) {
    96     $writable = false;
    97 } else {
    98     if ( ( ! file_exists( $home_path . '.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path . '.htaccess' ) ) {
    99         $writable = true;
    100     } else {
    101         $writable        = false;
    102         $existing_rules  = array_filter( extract_from_markers( $home_path . '.htaccess', 'WordPress' ) );
    103         $new_rules       = array_filter( explode( "\n", $wp_rewrite->mod_rewrite_rules() ) );
    104         $update_required = ( $new_rules !== $existing_rules );
    105     }
    106 }
    107 
    108 $using_index_permalinks = $wp_rewrite->using_index_permalinks();
     85$category_base = get_option( 'category_base' );
     86$tag_base      = get_option( 'tag_base' );
     87
     88$structure_updated        = false;
     89$htaccess_update_required = false;
    10990
    11091if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) ) {
     
    11293
    11394    if ( isset( $_POST['permalink_structure'] ) ) {
    114         if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] ) {
     95        if ( isset( $_POST['selection'] ) && 'custom' !== $_POST['selection'] ) {
    11596            $permalink_structure = $_POST['selection'];
    11697        } else {
     
    130111
    131112        $wp_rewrite->set_permalink_structure( $permalink_structure );
     113
     114        $structure_updated = true;
    132115    }
    133116
    134117    if ( isset( $_POST['category_base'] ) ) {
    135118        $category_base = $_POST['category_base'];
     119
    136120        if ( ! empty( $category_base ) ) {
    137121            $category_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
    138122        }
     123
    139124        $wp_rewrite->set_category_base( $category_base );
    140125    }
     
    142127    if ( isset( $_POST['tag_base'] ) ) {
    143128        $tag_base = $_POST['tag_base'];
     129
    144130        if ( ! empty( $tag_base ) ) {
    145131            $tag_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
    146132        }
     133
    147134        $wp_rewrite->set_tag_base( $tag_base );
    148135    }
    149 
     136}
     137
     138if ( $iis7_permalinks ) {
     139    if ( ( ! file_exists( $home_path . 'web.config' ) && win_is_writable( $home_path ) ) || win_is_writable( $home_path . 'web.config' ) ) {
     140        $writable = true;
     141    } else {
     142        $writable = false;
     143    }
     144} elseif ( $is_nginx ) {
     145    $writable = false;
     146} else {
     147    if ( ( ! file_exists( $home_path . '.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path . '.htaccess' ) ) {
     148        $writable = true;
     149    } else {
     150        $writable       = false;
     151        $existing_rules = array_filter( extract_from_markers( $home_path . '.htaccess', 'WordPress' ) );
     152        $new_rules      = array_filter( explode( "\n", $wp_rewrite->mod_rewrite_rules() ) );
     153
     154        $htaccess_update_required = ( $new_rules !== $existing_rules );
     155    }
     156}
     157
     158$using_index_permalinks = $wp_rewrite->using_index_permalinks();
     159
     160if ( $structure_updated ) {
    150161    $message = __( 'Permalink structure updated.' );
    151162
     
    164175            );
    165176        }
    166     } elseif ( ! $is_nginx && $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) {
     177    } elseif ( ! $is_nginx && $permalink_structure && ! $using_index_permalinks && ! $writable && $htaccess_update_required ) {
    167178        $message = sprintf(
    168179            /* translators: %s: .htaccess */
     
    401412    <?php
    402413else :
    403     if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) :
     414    if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $htaccess_update_required ) :
    404415        ?>
    405416<p>
Note: See TracChangeset for help on using the changeset viewer.