Ticket #37667: 37667.diff
File 37667.diff, 10.3 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-post-type.php
325 325 public $rewrite; 326 326 327 327 /** 328 * The features supported by the post type .328 * The features supported by the post type, per post type definition. 329 329 * 330 330 * @since 4.6.0 331 331 * @access public … … 334 334 public $supports; 335 335 336 336 /** 337 * All features supported by the post type. 338 * 339 * @since 4.7.0 340 * @access private 341 * @var array $features 342 */ 343 private $features = array(); 344 345 /** 337 346 * Constructor. 338 347 * 339 348 * Will populate object properties from the provided arguments and assign other … … 511 520 */ 512 521 public function add_supports() { 513 522 if ( ! empty( $this->supports ) ) { 514 add_post_type_support( $this->name,$this->supports );523 $this->add_support( $this->supports ); 515 524 unset( $this->supports ); 516 525 } elseif ( false !== $this->supports ) { 517 526 // Add default features. 518 add_post_type_support( $this->name,array( 'title', 'editor' ) );527 $this->add_support( array( 'title', 'editor' ) ); 519 528 } 520 529 } 521 530 … … 602 611 } 603 612 604 613 /** 614 * Registers support of certain features for the post type. 615 * 616 * All core features are directly associated with a functional area of the edit 617 * screen, such as the editor or a meta box. Features include: 'title', 'editor', 618 * 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', 'page-attributes', 619 * 'thumbnail', 'custom-fields', and 'post-formats'. 620 * 621 * Additionally, the 'revisions' feature dictates whether the post type will 622 * store revisions, and the 'comments' feature dictates whether the comments 623 * count will show on the edit screen. 624 * 625 * @since 4.7.0 626 * @access public 627 * 628 * @param string|array $feature The feature being added, accepts an array of 629 * feature strings or a single string. 630 * @param bool $value Optional. The value to give to the feature. Default 631 * true. 632 * @param string $subtype Optional. A subtype to add this feature to. An 633 * empty value will add this feature to the overall 634 * post type. Default empty. 635 */ 636 public function add_support( $feature, $value = true, $subtype = '' ) { 637 $features = (array) $feature; 638 foreach ( $features as $feature ) { 639 $this->features[ $subtype ][ $feature ] = $value; 640 } 641 } 642 643 /** 644 * Removes support for a feature from the post type. 645 * 646 * @since 4.7.0 647 * @access public 648 * 649 * @param string $feature The feature being removed. 650 * @param string $subtype Optional. A subtype to remove this feature from. An 651 * empty value will remove this feature from the overall 652 * post type. Default empty. 653 */ 654 public function remove_support( $feature, $subtype = '' ) { 655 unset( $this->features[ $subtype ][ $feature ] ); 656 } 657 658 /** 659 * Gets all the post type features. 660 * 661 * @since 4.7.0 662 * @access public 663 * 664 * @param string $subtype Optional. A subtype to get its features. An 665 * empty value will return the overall post type 666 * features. Default empty. 667 * @return array Post type supports list. 668 */ 669 public function get_all_supports( $subtype = '' ) { 670 return $this->features[ $subtype ]; 671 } 672 673 /** 674 * Checks the post type's support for a given feature. 675 * 676 * @since 4.7.0 677 * @access public 678 * 679 * @param string $feature The feature being checked. 680 * @param string $subtype Optional. A subtype to check in its features. An 681 * empty value will check within the overall post type 682 * features. Default empty. 683 * @return bool Whether the post type supports the given feature. 684 */ 685 public function supports( $feature, $subtype = '' ) { 686 return isset( $this->features[ $subtype ][ $feature ] ); 687 } 688 689 /** 690 * Retrieves a list of post type and subtype names that support a specific feature. 691 * 692 * If the features are supported by the overall post type, the post type name is 693 * included in the list. If the features are supported by a specific subtype, a 694 * string consisting of post type name and subtype name delimited by a colon is 695 * included in the list. 696 * 697 * @since 4.7.0 698 * @access public 699 * 700 * @param array|string $feature Single feature or an array of features the post type should support. 701 * @param string $operator Optional. The logical operation to perform. 'or' means 702 * only one element from the array needs to match; 'and' 703 * means all elements must match; 'not' means no elements may 704 * match. Default 'and'. 705 * @return array A list of post type and subtype names. 706 */ 707 public function get_by_support( $feature, $operator = 'and' ) { 708 $features = array_fill_keys( (array) $feature, true ); 709 $subtypes = array_keys( wp_filter_object_list( $this->features, $features, $operator ) ); 710 711 $names = array(); 712 foreach ( $subtypes as $subtype ) { 713 if ( empty( $subtype ) ) { 714 $names[] = $this->name; 715 } else { 716 $names[] = $this->name . ':' . $subtype; 717 } 718 } 719 720 return $names; 721 } 722 723 /** 605 724 * Removes the features support for the post type. 606 725 * 607 726 * @since 4.6.0 608 727 * @access public 609 *610 * @global array $_wp_post_type_features Post type features.611 728 */ 612 729 public function remove_supports() { 613 global $_wp_post_type_features; 614 615 unset( $_wp_post_type_features[ $this->name ] ); 730 $this->features = array(); 616 731 } 617 732 618 733 /** -
src/wp-includes/post.php
1398 1398 * count will show on the edit screen. 1399 1399 * 1400 1400 * @since 3.0.0 1401 * @since 4.7.0 Uses `WP_Post_Type` to handle features. 1401 1402 * 1402 * @global array $_wp_post_type_features1403 *1404 1403 * @param string $post_type The post type for which to add the feature. 1405 1404 * @param string|array $feature The feature being added, accepts an array of 1406 1405 * feature strings or a single string. 1407 1406 */ 1408 1407 function add_post_type_support( $post_type, $feature ) { 1409 global $_wp_post_type_features; 1408 $subtype = ''; 1409 if ( strpos( $post_type, ':' ) ) { 1410 list( $post_type, $subtype ) = explode( ':', $post_type ); 1411 } 1410 1412 1411 $features = (array) $feature; 1412 foreach ($features as $feature) { 1413 if ( func_num_args() == 2 ) 1414 $_wp_post_type_features[$post_type][$feature] = true; 1415 else 1416 $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 ); 1413 $ptype_obj = get_post_type_object( $post_type ); 1414 if ( ! $ptype_obj ) { 1415 return; 1417 1416 } 1417 1418 if ( func_num_args() == 2 ) { 1419 $value = true; 1420 } else { 1421 $value = array_slice( func_get_args(), 2 ); 1422 } 1423 1424 $ptype_obj->add_support( $feature, $value, $subtype ); 1418 1425 } 1419 1426 1420 1427 /** 1421 1428 * Remove support for a feature from a post type. 1422 1429 * 1423 1430 * @since 3.0.0 1431 * @since 4.7.0 Uses `WP_Post_Type` to handle features. 1424 1432 * 1425 * @global array $_wp_post_type_features1426 *1427 1433 * @param string $post_type The post type for which to remove the feature. 1428 1434 * @param string $feature The feature being removed. 1429 1435 */ 1430 1436 function remove_post_type_support( $post_type, $feature ) { 1431 global $_wp_post_type_features; 1437 $subtype = ''; 1438 if ( strpos( $post_type, ':' ) ) { 1439 list( $post_type, $subtype ) = explode( ':', $post_type ); 1440 } 1432 1441 1433 unset( $_wp_post_type_features[ $post_type ][ $feature ] ); 1442 $ptype_obj = get_post_type_object( $post_type ); 1443 if ( ! $ptype_obj ) { 1444 return; 1445 } 1446 1447 $ptype_obj->remove_support( $feature, $subtype ); 1434 1448 } 1435 1449 1436 1450 /** 1437 1451 * Get all the post type features 1438 1452 * 1439 1453 * @since 3.4.0 1454 * @since 4.7.0 Uses `WP_Post_Type` to handle features. 1440 1455 * 1441 * @global array $_wp_post_type_features1442 *1443 1456 * @param string $post_type The post type. 1444 1457 * @return array Post type supports list. 1445 1458 */ 1446 1459 function get_all_post_type_supports( $post_type ) { 1447 global $_wp_post_type_features; 1460 $subtype = ''; 1461 if ( strpos( $post_type, ':' ) ) { 1462 list( $post_type, $subtype ) = explode( ':', $post_type ); 1463 } 1448 1464 1449 if ( isset( $_wp_post_type_features[$post_type] ) ) 1450 return $_wp_post_type_features[$post_type]; 1465 $ptype_obj = get_post_type_object( $post_type ); 1466 if ( ! $ptype_obj ) { 1467 return array(); 1468 } 1451 1469 1452 return array();1470 return $ptype_obj->get_all_supports( $subtype ); 1453 1471 } 1454 1472 1455 1473 /** 1456 1474 * Check a post type's support for a given feature. 1457 1475 * 1458 1476 * @since 3.0.0 1477 * @since 4.7.0 Uses `WP_Post_Type` to handle features. 1459 1478 * 1460 * @global array $_wp_post_type_features1461 *1462 1479 * @param string $post_type The post type being checked. 1463 1480 * @param string $feature The feature being checked. 1464 1481 * @return bool Whether the post type supports the given feature. 1465 1482 */ 1466 1483 function post_type_supports( $post_type, $feature ) { 1467 global $_wp_post_type_features; 1484 $subtype = ''; 1485 if ( strpos( $post_type, ':' ) ) { 1486 list( $post_type, $subtype ) = explode( ':', $post_type ); 1487 } 1468 1488 1469 return ( isset( $_wp_post_type_features[$post_type][$feature] ) ); 1489 $ptype_obj = get_post_type_object( $post_type ); 1490 if ( ! $ptype_obj ) { 1491 return false; 1492 } 1493 1494 return $ptype_obj->supports( $feature, $subtype ); 1470 1495 } 1471 1496 1472 1497 /** 1473 1498 * Retrieves a list of post type names that support a specific feature. 1474 1499 * 1475 1500 * @since 4.5.0 1501 * @since 4.7.0 Uses `WP_Post_Type` to handle features. 1476 1502 * 1477 * @global array $_wp_post_type_features Post type features1478 *1479 1503 * @param array|string $feature Single feature or an array of features the post types should support. 1480 1504 * @param string $operator Optional. The logical operation to perform. 'or' means 1481 1505 * only one element from the array needs to match; 'and' … … 1484 1508 * @return array A list of post type names. 1485 1509 */ 1486 1510 function get_post_types_by_support( $feature, $operator = 'and' ) { 1487 global $_wp_post_type_features;1511 $names = array(); 1488 1512 1489 $features = array_fill_keys( (array) $feature, true ); 1513 $ptype_objects = get_post_types( array(), 'objects' ); 1514 foreach ( $ptype_objects as $ptype_obj ) { 1515 $names = array_merge( $names, $ptype_obj->get_by_support( $feature, $operator ) ); 1516 } 1490 1517 1491 return array_keys( wp_filter_object_list( $_wp_post_type_features, $features, $operator ) );1518 return $names; 1492 1519 } 1493 1520 1494 1521 /**