Make WordPress Core

Ticket #10885: 10885.3.diff

File 10885.3.diff, 4.1 KB (added by ryan, 16 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 * Get a list of all registered post type objects.
     427 *
     428 * @package WordPress
     429 * @subpackage Post
     430 * @since 2.9.0
     431 * @uses $wp_post_types
     432 * @see register_post_type
     433 * @see get_post_types
     434 *
     435 * @param array|string $args An array of key => value arguments to match against the post types.
     436 *  Only post types having attributes that match all arguments are returned.
     437 * @return array A list of post type objects
     438 */
     439function get_post_type_objects( $args = array() ) {
     440        global $wp_post_types;
     441
     442        $post_types = array();
     443        foreach ( (array) $wp_post_types as $post_type ) {
     444                if ( empty($args) )
     445                        $post_types[] = $post_type;
     446                elseif ( array_intersect((array) $post_type, $args) )
     447                        $post_types[] = $post_type;
     448        }
     449
     450        return $post_types;
     451}
     452
     453/**
     454 * Get a list of all registered post types.
     455 *
     456 * @package WordPress
     457 * @subpackage Post
     458 * @since 2.9.0
     459 * @uses get_post_type_objects
     460 * @see register_post_type
     461 *
     462 * @param array|string $args An array of key => value arguments to match against the post types.
     463 *  Only post types having attributes that match all arguments are returned.
     464 * @return array A list of post type names
     465 */
     466function get_post_types( $args = array() ) {
     467        $type_objects = get_post_type_objects($args);
     468
     469        $types = array();
     470        foreach ( $type_objects as $type )
     471                $types[] = $type->name;
     472
     473        return $types;
     474}
     475
     476/**
     477 * Register a post type. Do not use before init.
     478 *
     479 * A simple function for creating or modifying a post type based on the
     480 * parameters given. The function will accept an array (second optional
     481 * parameter), along with a string for the post type name.
     482 *
     483 *
     484 * Optional $args contents:
     485 *
     486 * exclude_from_search - Whether to exclude posts with this post type from search results. Defaults to true.
     487 *
     488 * @package WordPress
     489 * @subpackage Post
     490 * @since 2.9.0
     491 * @uses $wp_post_types Inserts new post type object into the list
     492 *
     493 * @param string $post_type Name of the post type.
     494 * @param array|string $args See above description.
     495 */
     496function register_post_type($post_type, $args = array()) {
     497        global $wp_post_types;
     498
     499        if (!is_array($wp_post_types))
     500                $wp_post_types = array();
     501
     502        $defaults = array('exclude_from_search' => true);
     503        $args = wp_parse_args($args, $defaults);
     504
     505        $post_type = sanitize_user($post_type, true);
     506        $args['name'] = $post_type;
     507        $wp_post_types[$post_type] = (object) $args;
     508}
     509
     510/**
    411511 * Updates the post type for the post ID.
    412512 *
    413513 * 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                $exclude_post_types = '';
     2076                foreach ( get_post_types( array('exclude_from_search' => true) ) as $_wp_post_type )
     2077                        $exclude_post_types .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $_wp_post_type);
     2078
    20752079                if ( 'any' == $post_type ) {
    2076                         $where .= " AND $wpdb->posts.post_type != 'revision'";
     2080                        $where .= $exclude_post_types;
    20772081                } elseif ( ! empty( $post_type ) ) {
    20782082                        $where .= " AND $wpdb->posts.post_type = '$post_type'";
    20792083                } elseif ( $this->is_attachment ) {