Changeset 12719 for trunk/wp-includes/post.php
- Timestamp:
- 01/13/2010 06:49:56 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r12708 r12719 22 22 add_post_type_support('post', array('post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments') ); 23 23 add_post_type_support('page', array('post-thumbnails', 'page-attributes', 'custom-fields', 'comments') ); 24 25 register_post_status( 'publish', array('label' => _x('Published', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')) ); 26 register_post_status( 'future', array('label' => _x('Scheduled', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')) ); 27 register_post_status( 'draft', array('label' => _x('Draft', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')) ); 28 register_post_status( 'private', array('label' => _x('Private', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')) ); 29 register_post_status( 'trash', array('label' => _x('Trash', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')) ); 24 30 } 25 31 add_action( 'init', 'create_initial_post_types', 0 ); // highest priority … … 417 423 418 424 return $status; 425 } 426 427 /** 428 * Register a post type. Do not use before init. 429 * 430 * A simple function for creating or modifying a post status based on the 431 * parameters given. The function will accept an array (second optional 432 * parameter), along with a string for the post status name. 433 * 434 * 435 * Optional $args contents: 436 * 437 * label - A descriptive name for the post status marked for translation. Defaults to $post_status. 438 * public - Whether posts of this status should be shown in the admin UI. Defaults to true. 439 * exclude_from_search - Whether to exclude posts with this post status from search results. Defaults to true. 440 * 441 * @package WordPress 442 * @subpackage Post 443 * @since 3.0 444 * @uses $wp_post_statuses Inserts new post status object into the list 445 * 446 * @param string $post_status Name of the post status. 447 * @param array|string $args See above description. 448 */ 449 function register_post_status($post_status, $args = array()) { 450 global $wp_post_statuses; 451 452 if (!is_array($wp_post_statuses)) 453 $wp_post_statuses = array(); 454 455 // Args prefixed with an underscore are reserved for internal use. 456 $defaults = array('label' => false, 'label_count' => false, 'exclude_from_search' => true, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, '_show' => false); 457 $args = wp_parse_args($args, $defaults); 458 $args = (object) $args; 459 460 $post_status = sanitize_user($post_status, true); 461 $args->name = $post_status; 462 463 if ( false === $args->label ) 464 $args->label = $post_status; 465 466 if ( false === $args->label_count ) 467 $args->label_count = $args->label; 468 469 if ( !$args->_builtin && $args->public ) 470 $args->_show = true; 471 472 $wp_post_statuses[$post_status] = $args; 473 474 return $args; 475 } 476 477 /** 478 * Retrieve a post status object by name 479 * 480 * @package WordPress 481 * @subpackage Post 482 * @since 3.0 483 * @uses $wp_post_statuses 484 * @see register_post_status 485 * @see get_post_statuses 486 * 487 * @param string $post_type The name of a registered post status 488 * @return object A post status object 489 */ 490 function get_post_status_object( $post_status ) { 491 global $wp_post_statuses; 492 493 if ( empty($wp_post_statuses[$post_status]) ) 494 return null; 495 496 return $wp_post_statuses[$post_status]; 497 } 498 499 /** 500 * Get a list of all registered post status objects. 501 * 502 * @package WordPress 503 * @subpackage Post 504 * @since 3.0 505 * @uses $wp_post_statuses 506 * @see register_post_status 507 * @see get_post_status_object 508 * 509 * @param array|string $args An array of key => value arguments to match against the post statuses. 510 * Only post statuses having attributes that match all arguments are returned. 511 * @param string $output The type of output to return, either post status 'names' or 'objects'. 'names' is the default. 512 * @return array A list of post type names or objects 513 */ 514 function get_post_stati( $args = array(), $output = 'names' ) { 515 global $wp_post_statuses; 516 517 $do_names = false; 518 if ( 'names' == $output ) 519 $do_names = true; 520 521 $post_statuses = array(); 522 foreach ( (array) $wp_post_statuses as $post_status ) { 523 if ( empty($args) ) { 524 if ( $do_names ) 525 $post_statuses[] = $post_status->name; 526 else 527 $post_statuses[] = $post_status; 528 } elseif ( array_intersect_assoc((array) $post_status, $args) ) { 529 if ( $do_names ) 530 $post_statuses[] = $post_status->name; 531 else 532 $post_statuses[] = $post_status; 533 } 534 } 535 536 return $post_statuses; 419 537 } 420 538
Note: See TracChangeset
for help on using the changeset viewer.