WordPress.org

Make WordPress Core

Ticket #10885: 10885.diff

File 10885.diff, 2.8 KB (added by ryan, 5 years ago)
  • wp-includes/post.php

     
    77 * @since 1.5.0 
    88 */ 
    99 
     10// 
     11// Post Type Registration 
     12// 
     13 
    1014/** 
     15 * Creates the initial post types when 'init' action is fired. 
     16 */ 
     17function create_initial_post_types() { 
     18        register_post_type( 'post', array('exclude_from_search' => false) ); 
     19        register_post_type( 'page', array('exclude_from_search' => false) ); 
     20        register_post_type( 'attachment', array('exclude_from_search' => false) ); 
     21        register_post_type( 'revision', array('exclude_from_search' => true) ); 
     22} 
     23add_action( 'init', 'create_initial_post_types', 0 ); // highest priority 
     24 
     25/** 
    1126 * Retrieve attached file path based on attachment ID. 
    1227 * 
    1328 * You can optionally send it through the 'get_attached_file' filter, but by 
     
    408423} 
    409424 
    410425/** 
     426 * Register a post type. Do not use before init. 
     427 * 
     428 * A simple function for creating or modifying a post type based on the 
     429 * parameters given. The function will accept an array (second optional 
     430 * parameter), along with a string for the post type name. 
     431 * 
     432 * 
     433 * Optional $args contents: 
     434 * 
     435 * exclude_from_search - Whether to exclude posts with this post type from search results. Defaults to true. 
     436 *  
     437 * @package WordPress 
     438 * @subpackage Post 
     439 * @since 2.9.0 
     440 * @uses $wp_post_types Inserts new post type object into the list 
     441 * 
     442 * @param string $post_type Name of the post type. 
     443 * @param array|string $args See above description. 
     444 */ 
     445function register_post_type($post_type, $args = array()) { 
     446        global $wp_post_types; 
     447 
     448        if (!is_array($wp_post_types)) 
     449                $wp_post_types = array(); 
     450 
     451        $defaults = array('exclude_from_search' => true); 
     452        $args = wp_parse_args($args, $defaults); 
     453 
     454        $post_type = sanitize_user($post_type, true); 
     455        $args['name'] = $post_type; 
     456        $wp_post_types[$post_type] = (object) $args; 
     457} 
     458 
     459/** 
    411460 * Updates the post type for the post ID. 
    412461 * 
    413462 * The page or post cache will be cleaned for the post ID. 
  • wp-includes/query.php

     
    20722072 
    20732073                $post_type_cap = $post_type; 
    20742074 
     2075                global $wp_post_types; 
     2076                $exclude_post_types = ''; 
     2077                foreach ( $wp_post_types as $_wp_post_type ) { 
     2078                        if ( $_wp_post_type->exclude_from_search ) 
     2079                                $exclude_post_types .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $_wp_post_type->name); 
     2080                } 
    20752081                if ( 'any' == $post_type ) { 
    2076                         $where .= " AND $wpdb->posts.post_type != 'revision'"; 
     2082                        $where .= $exclude_post_types; 
    20772083                } elseif ( ! empty( $post_type ) ) { 
    20782084                        $where .= " AND $wpdb->posts.post_type = '$post_type'"; 
    20792085                } elseif ( $this->is_attachment ) {