WordPress.org

Make WordPress Core

Ticket #18450: 18450.2.diff

File 18450.2.diff, 5.3 KB (added by scribu, 3 years ago)
  • wp-includes/post.php

    diff --git a/wp-includes/post.php b/wp-includes/post.php
    index 5eae599..17b5fa5 100644
    a b function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) 
    908908 * @return object|WP_Error the registered post type object, or an error object 
    909909 */ 
    910910function register_post_type($post_type, $args = array()) { 
    911         global $wp_post_types, $wp_rewrite, $wp; 
     911        global $wp_post_types, $wp; 
    912912 
    913913        if ( !is_array($wp_post_types) ) 
    914914                $wp_post_types = array(); 
    function register_post_type($post_type, $args = array()) { 
    985985                $wp->add_query_var($args->query_var); 
    986986        } 
    987987 
    988         if ( false !== $args->rewrite && ( is_admin() || '' != get_option('permalink_structure') ) ) { 
     988        if ( $args->register_meta_box_cb ) 
     989                add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1); 
     990 
     991        $args->labels = get_post_type_labels( $args ); 
     992        $args->label = $args->labels->name; 
     993 
     994        $wp_post_types[$post_type] = $args; 
     995 
     996        add_action( 'future_' . $post_type, '_future_post_hook', 5, 2 ); 
     997 
     998        foreach ( $args->taxonomies as $taxonomy ) { 
     999                register_taxonomy_for_object_type( $taxonomy, $post_type ); 
     1000        } 
     1001 
     1002        return $args; 
     1003} 
     1004 
     1005function _post_type_rewrite_rules() { 
     1006        global $wp_rewrite; 
     1007 
     1008        if ( '' == get_option('permalink_structure') ) 
     1009                return; 
     1010 
     1011        foreach ( get_post_types( array( 'rewrite' => false ), 'objects', 'not' ) as $post_type => $args ) { 
    9891012                if ( ! is_array( $args->rewrite ) ) 
    9901013                        $args->rewrite = array(); 
    9911014                if ( empty( $args->rewrite['slug'] ) ) 
    function register_post_type($post_type, $args = array()) { 
    10211044 
    10221045                $wp_rewrite->add_permastruct($post_type, "{$args->rewrite['slug']}/%$post_type%", $args->rewrite['with_front'], $args->permalink_epmask); 
    10231046        } 
    1024  
    1025         if ( $args->register_meta_box_cb ) 
    1026                 add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1); 
    1027  
    1028         $args->labels = get_post_type_labels( $args ); 
    1029         $args->label = $args->labels->name; 
    1030  
    1031         $wp_post_types[$post_type] = $args; 
    1032  
    1033         add_action( 'future_' . $post_type, '_future_post_hook', 5, 2 ); 
    1034  
    1035         foreach ( $args->taxonomies as $taxonomy ) { 
    1036                 register_taxonomy_for_object_type( $taxonomy, $post_type ); 
    1037         } 
    1038  
    1039         return $args; 
    10401047} 
     1048add_action( 'pre_flush_rewrite_rules', '_post_type_rewrite_rules', 9 ); 
    10411049 
    10421050/** 
    10431051 * Builds an object with all post type capabilities out of a post type object 
  • wp-includes/rewrite.php

    diff --git a/wp-includes/rewrite.php b/wp-includes/rewrite.php
    index 4502db1..355c0ad 100644
    a b class WP_Rewrite { 
    18571857         * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard). 
    18581858         */ 
    18591859        function flush_rules($hard = true) { 
     1860                do_action( 'pre_flush_rewrite_rules', $hard ); 
    18601861                delete_option('rewrite_rules'); 
    18611862                $this->wp_rewrite_rules(); 
    18621863                if ( $hard && function_exists('save_mod_rewrite_rules') ) 
  • wp-includes/taxonomy.php

    diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php
    index dee7af8..97e08ed 100644
    a b function is_taxonomy_hierarchical($taxonomy) { 
    292292 * @param array|string $args See above description for the two keys values. 
    293293 */ 
    294294function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 
    295         global $wp_taxonomies, $wp_rewrite, $wp; 
     295        global $wp_taxonomies, $wp; 
    296296 
    297297        if ( ! is_array($wp_taxonomies) ) 
    298298                $wp_taxonomies = array(); 
    function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 
    318318                $wp->add_query_var($args['query_var']); 
    319319        } 
    320320 
    321         if ( false !== $args['rewrite'] && '' != get_option('permalink_structure') ) { 
    322                 $args['rewrite'] = wp_parse_args($args['rewrite'], array( 
    323                         'slug' => sanitize_title_with_dashes($taxonomy), 
    324                         'with_front' => true, 
    325                         'hierarchical' => false 
    326                 )); 
    327  
    328                 if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] ) 
    329                         $tag = '(.+?)'; 
    330                 else 
    331                         $tag = '([^/]+)'; 
    332  
    333                 $wp_rewrite->add_rewrite_tag("%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term="); 
    334                 $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']); 
    335         } 
    336  
    337321        if ( is_null($args['show_ui']) ) 
    338322                $args['show_ui'] = $args['public']; 
    339323 
    function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 
    365349        add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term'); 
    366350} 
    367351 
     352function _taxonomy_rewrite_rules() { 
     353        global $wp_rewrite; 
     354 
     355        if ( '' == get_option('permalink_structure') ) 
     356                return; 
     357 
     358        foreach ( get_taxonomies( array( 'rewrite' => false ), 'objects', 'not' ) as $taxonomy => $args ) { 
     359                $args->rewrite = wp_parse_args( $args->rewrite, array( 
     360                        'slug' => sanitize_title_with_dashes( $taxonomy ), 
     361                        'with_front' => true, 
     362                        'hierarchical' => false 
     363                ) ); 
     364 
     365                if ( $args->hierarchical && $args->rewrite['hierarchical'] ) 
     366                        $tag = '(.+?)'; 
     367                else 
     368                        $tag = '([^/]+)'; 
     369 
     370                $wp_rewrite->add_rewrite_tag( "%$taxonomy%", $tag, $args->query_var ? "{$args->query_var}=" : "taxonomy=$taxonomy&term=" ); 
     371                $wp_rewrite->add_permastruct( $taxonomy, $args->rewrite['slug'] . "/%$taxonomy%", $args->rewrite['with_front'] ); 
     372        } 
     373} 
     374add_action( 'pre_flush_rewrite_rules', '_taxonomy_rewrite_rules', 9 ); 
     375 
    368376/** 
    369377 * Builds an object with all taxonomy labels out of a taxonomy object 
    370378 *