| 15 | * Creates the initial post types when 'init' action is fired. |
| 16 | */ |
| 17 | function 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 | } |
| 23 | add_action( 'init', 'create_initial_post_types', 0 ); // highest priority |
| 24 | |
| 25 | /** |
| 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 | * @param string $output The type of output to return, either post type 'names' or 'objects'. 'names' is the default. |
| 438 | * @return array A list of post type names or objects |
| 439 | */ |
| 440 | function get_post_types( $args = array(), $output = 'names' ) { |
| 441 | global $wp_post_types; |
| 442 | |
| 443 | $do_names = false; |
| 444 | if ( 'names' == $output ) |
| 445 | $do_names = true; |
| 446 | |
| 447 | $post_types = array(); |
| 448 | foreach ( (array) $wp_post_types as $post_type ) { |
| 449 | if ( empty($args) ) { |
| 450 | if ( $do_names ) |
| 451 | $post_types[] = $post_type->name; |
| 452 | else |
| 453 | $post_types[] = $post_type; |
| 454 | } elseif ( array_intersect((array) $post_type, $args) ) { |
| 455 | if ( $do_names ) |
| 456 | $post_types[] = $post_type->name; |
| 457 | else |
| 458 | $post_types[] = $post_type; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | return $post_types; |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * Register a post type. Do not use before init. |
| 467 | * |
| 468 | * A simple function for creating or modifying a post type based on the |
| 469 | * parameters given. The function will accept an array (second optional |
| 470 | * parameter), along with a string for the post type name. |
| 471 | * |
| 472 | * |
| 473 | * Optional $args contents: |
| 474 | * |
| 475 | * exclude_from_search - Whether to exclude posts with this post type from search results. Defaults to true. |
| 476 | * |
| 477 | * @package WordPress |
| 478 | * @subpackage Post |
| 479 | * @since 2.9.0 |
| 480 | * @uses $wp_post_types Inserts new post type object into the list |
| 481 | * |
| 482 | * @param string $post_type Name of the post type. |
| 483 | * @param array|string $args See above description. |
| 484 | */ |
| 485 | function register_post_type($post_type, $args = array()) { |
| 486 | global $wp_post_types; |
| 487 | |
| 488 | if (!is_array($wp_post_types)) |
| 489 | $wp_post_types = array(); |
| 490 | |
| 491 | $defaults = array('exclude_from_search' => true); |
| 492 | $args = wp_parse_args($args, $defaults); |
| 493 | |
| 494 | $post_type = sanitize_user($post_type, true); |
| 495 | $args['name'] = $post_type; |
| 496 | $wp_post_types[$post_type] = (object) $args; |
| 497 | } |
| 498 | |
| 499 | /** |