- Timestamp:
- 09/19/2019 02:04:51 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r46068 r46184 1440 1440 $data = array(); 1441 1441 1442 if ( in_array( 'id', $fields, true) ) {1442 if ( rest_is_field_included( 'id', $fields ) ) { 1443 1443 $data['id'] = $post->ID; 1444 1444 } 1445 1445 1446 if ( in_array( 'date', $fields, true) ) {1446 if ( rest_is_field_included( 'date', $fields ) ) { 1447 1447 $data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date ); 1448 1448 } 1449 1449 1450 if ( in_array( 'date_gmt', $fields, true) ) {1450 if ( rest_is_field_included( 'date_gmt', $fields ) ) { 1451 1451 // For drafts, `post_date_gmt` may not be set, indicating that the 1452 1452 // date of the draft should be updated each time it is saved (see … … 1461 1461 } 1462 1462 1463 if ( in_array( 'guid', $fields, true) ) {1463 if ( rest_is_field_included( 'guid', $fields ) ) { 1464 1464 $data['guid'] = array( 1465 1465 /** This filter is documented in wp-includes/post-template.php */ … … 1469 1469 } 1470 1470 1471 if ( in_array( 'modified', $fields, true) ) {1471 if ( rest_is_field_included( 'modified', $fields ) ) { 1472 1472 $data['modified'] = $this->prepare_date_response( $post->post_modified_gmt, $post->post_modified ); 1473 1473 } 1474 1474 1475 if ( in_array( 'modified_gmt', $fields, true) ) {1475 if ( rest_is_field_included( 'modified_gmt', $fields ) ) { 1476 1476 // For drafts, `post_modified_gmt` may not be set (see 1477 1477 // `post_date_gmt` comments above). In this case, shim the value … … 1486 1486 } 1487 1487 1488 if ( in_array( 'password', $fields, true) ) {1488 if ( rest_is_field_included( 'password', $fields ) ) { 1489 1489 $data['password'] = $post->post_password; 1490 1490 } 1491 1491 1492 if ( in_array( 'slug', $fields, true) ) {1492 if ( rest_is_field_included( 'slug', $fields ) ) { 1493 1493 $data['slug'] = $post->post_name; 1494 1494 } 1495 1495 1496 if ( in_array( 'status', $fields, true) ) {1496 if ( rest_is_field_included( 'status', $fields ) ) { 1497 1497 $data['status'] = $post->post_status; 1498 1498 } 1499 1499 1500 if ( in_array( 'type', $fields, true) ) {1500 if ( rest_is_field_included( 'type', $fields ) ) { 1501 1501 $data['type'] = $post->post_type; 1502 1502 } 1503 1503 1504 if ( in_array( 'link', $fields, true) ) {1504 if ( rest_is_field_included( 'link', $fields ) ) { 1505 1505 $data['link'] = get_permalink( $post->ID ); 1506 1506 } 1507 1507 1508 if ( in_array( 'title', $fields, true ) ) { 1508 if ( rest_is_field_included( 'title', $fields ) ) { 1509 $data['title'] = array(); 1510 } 1511 if ( rest_is_field_included( 'title.raw', $fields ) ) { 1512 $data['title']['raw'] = $post->post_title; 1513 } 1514 if ( rest_is_field_included( 'title.rendered', $fields ) ) { 1509 1515 add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); 1510 1516 1511 $data['title'] = array( 1512 'raw' => $post->post_title, 1513 'rendered' => get_the_title( $post->ID ), 1514 ); 1517 $data['title']['rendered'] = get_the_title( $post->ID ); 1515 1518 1516 1519 remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); … … 1526 1529 } 1527 1530 1528 if ( in_array( 'content', $fields, true ) ) { 1529 $data['content'] = array( 1530 'raw' => $post->post_content, 1531 /** This filter is documented in wp-includes/post-template.php */ 1532 'rendered' => post_password_required( $post ) ? '' : apply_filters( 'the_content', $post->post_content ), 1533 'protected' => (bool) $post->post_password, 1534 'block_version' => block_version( $post->post_content ), 1535 ); 1536 } 1537 1538 if ( in_array( 'excerpt', $fields, true ) ) { 1531 if ( rest_is_field_included( 'content', $fields ) ) { 1532 $data['content'] = array(); 1533 } 1534 if ( rest_is_field_included( 'content.raw', $fields ) ) { 1535 $data['content']['raw'] = $post->post_content; 1536 } 1537 if ( rest_is_field_included( 'content.rendered', $fields ) ) { 1538 /** This filter is documented in wp-includes/post-template.php */ 1539 $data['content']['rendered'] = post_password_required( $post ) ? '' : apply_filters( 'the_content', $post->post_content ); 1540 } 1541 if ( rest_is_field_included( 'content.protected', $fields ) ) { 1542 $data['content']['protected'] = (bool) $post->post_password; 1543 } 1544 if ( rest_is_field_included( 'content.block_version', $fields ) ) { 1545 $data['content']['block_version'] = block_version( $post->post_content ); 1546 } 1547 1548 if ( rest_is_field_included( 'excerpt', $fields ) ) { 1539 1549 /** This filter is documented in wp-includes/post-template.php */ 1540 1550 $excerpt = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) ); … … 1551 1561 } 1552 1562 1553 if ( in_array( 'author', $fields, true) ) {1563 if ( rest_is_field_included( 'author', $fields ) ) { 1554 1564 $data['author'] = (int) $post->post_author; 1555 1565 } 1556 1566 1557 if ( in_array( 'featured_media', $fields, true) ) {1567 if ( rest_is_field_included( 'featured_media', $fields ) ) { 1558 1568 $data['featured_media'] = (int) get_post_thumbnail_id( $post->ID ); 1559 1569 } 1560 1570 1561 if ( in_array( 'parent', $fields, true) ) {1571 if ( rest_is_field_included( 'parent', $fields ) ) { 1562 1572 $data['parent'] = (int) $post->post_parent; 1563 1573 } 1564 1574 1565 if ( in_array( 'menu_order', $fields, true) ) {1575 if ( rest_is_field_included( 'menu_order', $fields ) ) { 1566 1576 $data['menu_order'] = (int) $post->menu_order; 1567 1577 } 1568 1578 1569 if ( in_array( 'comment_status', $fields, true) ) {1579 if ( rest_is_field_included( 'comment_status', $fields ) ) { 1570 1580 $data['comment_status'] = $post->comment_status; 1571 1581 } 1572 1582 1573 if ( in_array( 'ping_status', $fields, true) ) {1583 if ( rest_is_field_included( 'ping_status', $fields ) ) { 1574 1584 $data['ping_status'] = $post->ping_status; 1575 1585 } 1576 1586 1577 if ( in_array( 'sticky', $fields, true) ) {1587 if ( rest_is_field_included( 'sticky', $fields ) ) { 1578 1588 $data['sticky'] = is_sticky( $post->ID ); 1579 1589 } 1580 1590 1581 if ( in_array( 'template', $fields, true) ) {1591 if ( rest_is_field_included( 'template', $fields ) ) { 1582 1592 $template = get_page_template_slug( $post->ID ); 1583 1593 if ( $template ) { … … 1588 1598 } 1589 1599 1590 if ( in_array( 'format', $fields, true) ) {1600 if ( rest_is_field_included( 'format', $fields ) ) { 1591 1601 $data['format'] = get_post_format( $post->ID ); 1592 1602 … … 1597 1607 } 1598 1608 1599 if ( in_array( 'meta', $fields, true) ) {1609 if ( rest_is_field_included( 'meta', $fields ) ) { 1600 1610 $data['meta'] = $this->meta->get_value( $post->ID, $request ); 1601 1611 } … … 1606 1616 $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; 1607 1617 1608 if ( in_array( $base, $fields, true) ) {1618 if ( rest_is_field_included( $base, $fields ) ) { 1609 1619 $terms = get_the_terms( $post, $taxonomy->name ); 1610 1620 $data[ $base ] = $terms ? array_values( wp_list_pluck( $terms, 'term_id' ) ) : array(); … … 1614 1624 $post_type_obj = get_post_type_object( $post->post_type ); 1615 1625 if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) { 1616 $permalink_template_requested = in_array( 'permalink_template', $fields, true);1617 $generated_slug_requested = in_array( 'generated_slug', $fields, true);1626 $permalink_template_requested = rest_is_field_included( 'permalink_template', $fields ); 1627 $generated_slug_requested = rest_is_field_included( 'generated_slug', $fields ); 1618 1628 1619 1629 if ( $permalink_template_requested || $generated_slug_requested ) {
Note: See TracChangeset
for help on using the changeset viewer.