WordPress.org

Make WordPress Core

Ticket #18450: 18450.diff

File 18450.diff, 2.9 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') )