Make WordPress Core

Ticket #9296: 9296.2.diff

File 9296.2.diff, 5.6 KB (added by SergeyBiryukov, 12 years ago)

Refreshed

  • wp-admin/options-permalink.php

     
    8383if ( is_multisite() && !is_subdomain_install() && is_main_site() )
    8484        $blog_prefix = '/blog';
    8585
    86 if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
    87         check_admin_referer('update-permalink');
    88 
    89         if ( isset( $_POST['permalink_structure'] ) ) {
    90                 if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] )
    91                         $permalink_structure = $_POST['selection'];
    92                 else
    93                         $permalink_structure = $_POST['permalink_structure'];
    94 
    95                 if ( ! empty( $permalink_structure ) ) {
    96                         $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) );
    97                         if ( $prefix && $blog_prefix )
    98                                 $permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure );
    99                         else
    100                                 $permalink_structure = $blog_prefix . $permalink_structure;
    101                 }
    102                 $wp_rewrite->set_permalink_structure( $permalink_structure );
    103         }
    104 
    105         if ( isset( $_POST['category_base'] ) ) {
    106                 $category_base = $_POST['category_base'];
    107                 if ( ! empty( $category_base ) )
    108                         $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
    109                 $wp_rewrite->set_category_base( $category_base );
    110         }
    111 
    112         if ( isset( $_POST['tag_base'] ) ) {
    113                 $tag_base = $_POST['tag_base'];
    114                 if ( ! empty( $tag_base ) )
    115                         $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
    116                 $wp_rewrite->set_tag_base( $tag_base );
    117         }
    118 
    119         create_initial_taxonomies();
    120 }
    121 
    122 $permalink_structure = get_option('permalink_structure');
    123 $category_base = get_option('category_base');
     86$permalink_structure = get_option( 'permalink_structure' );
     87$category_base = get_option( 'category_base' );
    12488$tag_base = get_option( 'tag_base' );
    12589
    12690if ( $iis7_permalinks ) {
     
    142106
    143107flush_rewrite_rules();
    144108
    145 if (isset($_POST['submit'])) : ?>
     109if ( isset( $_GET['settings-updated'] ) ) : ?>
    146110<div id="message" class="updated"><p><?php
    147111if ( ! is_multisite() ) {
    148112        if ( $iis7_permalinks ) {
     
    169133<?php screen_icon(); ?>
    170134<h2><?php echo esc_html( $title ); ?></h2>
    171135
    172 <form name="form" action="options-permalink.php" method="post">
    173 <?php wp_nonce_field('update-permalink') ?>
     136<form name="form" action="options.php" method="post">
     137<?php settings_fields( 'permalink' ); ?>
    174138
    175139  <p><?php _e('By default WordPress uses web <abbr title="Universal Resource Locator">URL</abbr>s which have question marks and lots of numbers in them, however WordPress offers you the ability to create a custom URL structure for your permalinks and archives. This can improve the aesthetics, usability, and forward-compatibility of your links. A <a href="http://codex.wordpress.org/Using_Permalinks">number of tags are available</a>, and here are some examples to get you started.'); ?></p>
    176140
  • wp-admin/options.php

     
    6565        'privacy' => array( 'blog_public' ),
    6666        'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'blog_charset', 'show_on_front', 'page_on_front', 'page_for_posts' ),
    6767        'writing' => array( 'default_post_edit_rows', 'use_smilies', 'default_category', 'default_email_category', 'use_balanceTags', 'default_link_category', 'default_post_format', 'enable_app', 'enable_xmlrpc' ),
    68         'options' => array( '' ) );
     68        'options' => array( '' ),
     69        'permalink' => array( 'permalink_structure', 'category_base', 'tag_base' ) );
    6970
    7071$mail_options = array('mailserver_url', 'mailserver_port', 'mailserver_login', 'mailserver_pass');
    7172$uploads_options = array('uploads_use_yearmonth_folders', 'upload_path', 'upload_url_path');
     
    132133                        $_POST['timezone_string'] = '';
    133134                }
    134135        }
     136       
     137        if ( 'permalink' == $option_page ) {
     138                if ( isset( $permalink_structure ) || isset( $category_base ) ) {
    135139
     140                        if ( isset( $permalink_structure ) ) {
     141                                if ( isset( $selection ) && 'custom' != $selection )
     142                                        $permalink_structure = $selection;
     143                               
     144                                if ( ! empty( $permalink_structure ) ) {
     145                                        $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) );
     146                                        if ( $prefix && $blog_prefix )
     147                                                $permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure );
     148                                        else
     149                                                $permalink_structure = $blog_prefix . $permalink_structure;
     150                                }
     151                                $wp_rewrite->set_permalink_structure( $permalink_structure );
     152                        }
     153
     154                        if ( isset( $category_base ) ) {
     155                                if ( ! empty( $category_base ) )
     156                                        $category_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
     157                                $wp_rewrite->set_category_base( $category_base );
     158                        }
     159
     160                        if ( isset( $tag_base ) ) {
     161                                if ( ! empty( $tag_base ) )
     162                                        $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
     163                                $wp_rewrite->set_tag_base( $tag_base );
     164                        }
     165
     166                        create_initial_taxonomies();
     167                }
     168        }
     169
    136170        if ( $options ) {
    137171                foreach ( $options as $option ) {
    138172                        if ( $unregistered )
     
    153187         * Handle settings errors and return to options page
    154188         */
    155189        // If no settings errors were registered add a general 'updated' message.
    156         if ( !count( get_settings_errors() ) )
     190        if ( !count( get_settings_errors() ) && 'permalink' != $option_page )
    157191                add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
    158192        set_transient('settings_errors', get_settings_errors(), 30);
    159193