WordPress.org

Make WordPress Core

Ticket #12002: 12002.4.diff

File 12002.4.diff, 3.3 KB (added by jeremyfelt, 6 years ago)
  • src/wp-admin/includes/ms.php

     
    616616add_action( 'network_admin_notices', 'site_admin_notice' );
    617617
    618618function avoid_blog_page_permalink_collision( $data, $postarr ) {
    619         if ( is_subdomain_install() )
     619        if ( is_subdomain_install() || ! is_main_site() || empty( $data['post_name'] ) ) {
    620620                return $data;
    621         if ( $data['post_type'] != 'page' )
     621        }
     622
     623        $blog_prefix = apply_filters( 'ms_blog_prefix', '/blog' );
     624
     625        if ( ! empty( $blog_prefix ) ) {
    622626                return $data;
    623         if ( !isset( $data['post_name'] ) || $data['post_name'] == '' )
     627        }
     628
     629        // Ignore it if the post type is not public
     630        if ( ! in_array( $data['post_type'], get_post_types( array( 'public' => true ) ) ) ) {
    624631                return $data;
    625         if ( !is_main_site() )
    626                 return $data;
     632        }
    627633
    628634        $post_name = $data['post_name'];
    629635        $c = 0;
    630         while( $c < 10 && get_id_from_blogname( $post_name ) ) {
     636        while ( $c < 10 && get_id_from_blogname( $post_name ) ) {
    631637                $post_name .= mt_rand( 1, 10 );
    632638                $c ++;
    633639        }
     640
    634641        if ( $post_name != $data['post_name'] ) {
    635642                $data['post_name'] = $post_name;
    636643        }
     644
    637645        return $data;
    638646}
    639647add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
  • src/wp-admin/options-permalink.php

     
    7575$iis7_permalinks = iis7_supports_permalinks();
    7676
    7777$prefix = $blog_prefix = '';
    78 if ( ! got_url_rewrite() )
     78if ( ! got_url_rewrite() ) {
    7979        $prefix = '/index.php';
    80 if ( is_multisite() && !is_subdomain_install() && is_main_site() )
    81         $blog_prefix = '/blog';
     80}
    8281
     82if ( is_multisite() && ! is_subdomain_install() && is_main_site() ) {
     83        $blog_prefix = apply_filters( 'ms_blog_prefix', '/blog' );
     84        if ( ! empty( $blog_prefix ) && '/' !== $blog_prefix[0] ) {
     85                $blog_prefix = '/' . $blog_prefix;
     86        }
     87}
     88
    8389if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
    8490        check_admin_referer('update-permalink');
    8591
     
    179185  <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>
    180186
    181187<?php
    182 if ( is_multisite() && !is_subdomain_install() && is_main_site() ) {
    183         $permalink_structure = preg_replace( '|^/?blog|', '', $permalink_structure );
    184         $category_base = preg_replace( '|^/?blog|', '', $category_base );
    185         $tag_base = preg_replace( '|^/?blog|', '', $tag_base );
     188if ( is_multisite() && ! is_subdomain_install() && is_main_site() && ! empty( $blog_prefix ) ) {
     189        $blog_prefix_base = '|^/?' . substr( $blog_prefix, 1 ) . '|';
     190
     191        $permalink_structure = preg_replace( $blog_prefix_base, '', $permalink_structure );
     192        $category_base = preg_replace( $blog_prefix_base, '', $category_base );
     193        $tag_base = preg_replace( $blog_prefix_base, '', $tag_base );
    186194}
    187195
    188196$structures = array(