Changeset 43445 for branches/4.9/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
- Timestamp:
- 07/13/2018 06:50:51 AM (7 years ago)
- Location:
- branches/4.9
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/4.9
-
branches/4.9/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r43442 r43445 1401 1401 setup_postdata( $post ); 1402 1402 1403 $ schema = $this->get_item_schema();1403 $fields = $this->get_fields_for_response( $request ); 1404 1404 1405 1405 // Base fields for every post. 1406 1406 $data = array(); 1407 1407 1408 if ( ! empty( $schema['properties']['id']) ) {1408 if ( in_array( 'id', $fields, true ) ) { 1409 1409 $data['id'] = $post->ID; 1410 1410 } 1411 1411 1412 if ( ! empty( $schema['properties']['date']) ) {1412 if ( in_array( 'date', $fields, true ) ) { 1413 1413 $data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date ); 1414 1414 } 1415 1415 1416 if ( ! empty( $schema['properties']['date_gmt']) ) {1416 if ( in_array( 'date_gmt', $fields, true ) ) { 1417 1417 // For drafts, `post_date_gmt` may not be set, indicating that the 1418 1418 // date of the draft should be updated each time it is saved (see … … 1427 1427 } 1428 1428 1429 if ( ! empty( $schema['properties']['guid']) ) {1429 if ( in_array( 'guid', $fields, true ) ) { 1430 1430 $data['guid'] = array( 1431 1431 /** This filter is documented in wp-includes/post-template.php */ … … 1435 1435 } 1436 1436 1437 if ( ! empty( $schema['properties']['modified']) ) {1437 if ( in_array( 'modified', $fields, true ) ) { 1438 1438 $data['modified'] = $this->prepare_date_response( $post->post_modified_gmt, $post->post_modified ); 1439 1439 } 1440 1440 1441 if ( ! empty( $schema['properties']['modified_gmt']) ) {1441 if ( in_array( 'modified_gmt', $fields, true ) ) { 1442 1442 // For drafts, `post_modified_gmt` may not be set (see 1443 1443 // `post_date_gmt` comments above). In this case, shim the value … … 1452 1452 } 1453 1453 1454 if ( ! empty( $schema['properties']['password']) ) {1454 if ( in_array( 'password', $fields, true ) ) { 1455 1455 $data['password'] = $post->post_password; 1456 1456 } 1457 1457 1458 if ( ! empty( $schema['properties']['slug']) ) {1458 if ( in_array( 'slug', $fields, true ) ) { 1459 1459 $data['slug'] = $post->post_name; 1460 1460 } 1461 1461 1462 if ( ! empty( $schema['properties']['status']) ) {1462 if ( in_array( 'status', $fields, true ) ) { 1463 1463 $data['status'] = $post->post_status; 1464 1464 } 1465 1465 1466 if ( ! empty( $schema['properties']['type']) ) {1466 if ( in_array( 'type', $fields, true ) ) { 1467 1467 $data['type'] = $post->post_type; 1468 1468 } 1469 1469 1470 if ( ! empty( $schema['properties']['link']) ) {1470 if ( in_array( 'link', $fields, true ) ) { 1471 1471 $data['link'] = get_permalink( $post->ID ); 1472 1472 } 1473 1473 1474 if ( ! empty( $schema['properties']['title']) ) {1474 if ( in_array( 'title', $fields, true ) ) { 1475 1475 add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); 1476 1476 … … 1492 1492 } 1493 1493 1494 if ( ! empty( $schema['properties']['content']) ) {1494 if ( in_array( 'content', $fields, true ) ) { 1495 1495 $data['content'] = array( 1496 1496 'raw' => $post->post_content, … … 1501 1501 } 1502 1502 1503 if ( ! empty( $schema['properties']['excerpt']) ) {1503 if ( in_array( 'excerpt', $fields, true ) ) { 1504 1504 /** This filter is documented in wp-includes/post-template.php */ 1505 1505 $excerpt = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) ); … … 1516 1516 } 1517 1517 1518 if ( ! empty( $schema['properties']['author']) ) {1518 if ( in_array( 'author', $fields, true ) ) { 1519 1519 $data['author'] = (int) $post->post_author; 1520 1520 } 1521 1521 1522 if ( ! empty( $schema['properties']['featured_media']) ) {1522 if ( in_array( 'featured_media', $fields, true ) ) { 1523 1523 $data['featured_media'] = (int) get_post_thumbnail_id( $post->ID ); 1524 1524 } 1525 1525 1526 if ( ! empty( $schema['properties']['parent']) ) {1526 if ( in_array( 'parent', $fields, true ) ) { 1527 1527 $data['parent'] = (int) $post->post_parent; 1528 1528 } 1529 1529 1530 if ( ! empty( $schema['properties']['menu_order']) ) {1530 if ( in_array( 'menu_order', $fields, true ) ) { 1531 1531 $data['menu_order'] = (int) $post->menu_order; 1532 1532 } 1533 1533 1534 if ( ! empty( $schema['properties']['comment_status']) ) {1534 if ( in_array( 'comment_status', $fields, true ) ) { 1535 1535 $data['comment_status'] = $post->comment_status; 1536 1536 } 1537 1537 1538 if ( ! empty( $schema['properties']['ping_status']) ) {1538 if ( in_array( 'ping_status', $fields, true ) ) { 1539 1539 $data['ping_status'] = $post->ping_status; 1540 1540 } 1541 1541 1542 if ( ! empty( $schema['properties']['sticky']) ) {1542 if ( in_array( 'sticky', $fields, true ) ) { 1543 1543 $data['sticky'] = is_sticky( $post->ID ); 1544 1544 } 1545 1545 1546 if ( ! empty( $schema['properties']['template']) ) {1546 if ( in_array( 'template', $fields, true ) ) { 1547 1547 if ( $template = get_page_template_slug( $post->ID ) ) { 1548 1548 $data['template'] = $template; … … 1552 1552 } 1553 1553 1554 if ( ! empty( $schema['properties']['format']) ) {1554 if ( in_array( 'format', $fields, true ) ) { 1555 1555 $data['format'] = get_post_format( $post->ID ); 1556 1556 … … 1561 1561 } 1562 1562 1563 if ( ! empty( $schema['properties']['meta']) ) {1563 if ( in_array( 'meta', $fields, true ) ) { 1564 1564 $data['meta'] = $this->meta->get_value( $post->ID, $request ); 1565 1565 } … … 1570 1570 $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; 1571 1571 1572 if ( ! empty( $schema['properties'][ $base ]) ) {1572 if ( in_array( $base, $fields, true ) ) { 1573 1573 $terms = get_the_terms( $post, $taxonomy->name ); 1574 1574 $data[ $base ] = $terms ? array_values( wp_list_pluck( $terms, 'term_id' ) ) : array();
Note: See TracChangeset
for help on using the changeset viewer.