- Timestamp:
- 05/02/2018 01:24:30 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r42678 r43087 1409 1409 setup_postdata( $post ); 1410 1410 1411 $ schema = $this->get_item_schema();1411 $fields = $this->get_fields_for_response( $request ); 1412 1412 1413 1413 // Base fields for every post. 1414 1414 $data = array(); 1415 1415 1416 if ( ! empty( $schema['properties']['id']) ) {1416 if ( in_array( 'id', $fields, true ) ) { 1417 1417 $data['id'] = $post->ID; 1418 1418 } 1419 1419 1420 if ( ! empty( $schema['properties']['date']) ) {1420 if ( in_array( 'date', $fields, true ) ) { 1421 1421 $data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date ); 1422 1422 } 1423 1423 1424 if ( ! empty( $schema['properties']['date_gmt']) ) {1424 if ( in_array( 'date_gmt', $fields, true ) ) { 1425 1425 // For drafts, `post_date_gmt` may not be set, indicating that the 1426 1426 // date of the draft should be updated each time it is saved (see … … 1435 1435 } 1436 1436 1437 if ( ! empty( $schema['properties']['guid']) ) {1437 if ( in_array( 'guid', $fields, true ) ) { 1438 1438 $data['guid'] = array( 1439 1439 /** This filter is documented in wp-includes/post-template.php */ … … 1443 1443 } 1444 1444 1445 if ( ! empty( $schema['properties']['modified']) ) {1445 if ( in_array( 'modified', $fields, true ) ) { 1446 1446 $data['modified'] = $this->prepare_date_response( $post->post_modified_gmt, $post->post_modified ); 1447 1447 } 1448 1448 1449 if ( ! empty( $schema['properties']['modified_gmt']) ) {1449 if ( in_array( 'modified_gmt', $fields, true ) ) { 1450 1450 // For drafts, `post_modified_gmt` may not be set (see 1451 1451 // `post_date_gmt` comments above). In this case, shim the value … … 1460 1460 } 1461 1461 1462 if ( ! empty( $schema['properties']['password']) ) {1462 if ( in_array( 'password', $fields, true ) ) { 1463 1463 $data['password'] = $post->post_password; 1464 1464 } 1465 1465 1466 if ( ! empty( $schema['properties']['slug']) ) {1466 if ( in_array( 'slug', $fields, true ) ) { 1467 1467 $data['slug'] = $post->post_name; 1468 1468 } 1469 1469 1470 if ( ! empty( $schema['properties']['status']) ) {1470 if ( in_array( 'status', $fields, true ) ) { 1471 1471 $data['status'] = $post->post_status; 1472 1472 } 1473 1473 1474 if ( ! empty( $schema['properties']['type']) ) {1474 if ( in_array( 'type', $fields, true ) ) { 1475 1475 $data['type'] = $post->post_type; 1476 1476 } 1477 1477 1478 if ( ! empty( $schema['properties']['link']) ) {1478 if ( in_array( 'link', $fields, true ) ) { 1479 1479 $data['link'] = get_permalink( $post->ID ); 1480 1480 } 1481 1481 1482 if ( ! empty( $schema['properties']['title']) ) {1482 if ( in_array( 'title', $fields, true ) ) { 1483 1483 add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); 1484 1484 … … 1500 1500 } 1501 1501 1502 if ( ! empty( $schema['properties']['content']) ) {1502 if ( in_array( 'content', $fields, true ) ) { 1503 1503 $data['content'] = array( 1504 1504 'raw' => $post->post_content, … … 1509 1509 } 1510 1510 1511 if ( ! empty( $schema['properties']['excerpt']) ) {1511 if ( in_array( 'excerpt', $fields, true ) ) { 1512 1512 /** This filter is documented in wp-includes/post-template.php */ 1513 1513 $excerpt = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) ); … … 1524 1524 } 1525 1525 1526 if ( ! empty( $schema['properties']['author']) ) {1526 if ( in_array( 'author', $fields, true ) ) { 1527 1527 $data['author'] = (int) $post->post_author; 1528 1528 } 1529 1529 1530 if ( ! empty( $schema['properties']['featured_media']) ) {1530 if ( in_array( 'featured_media', $fields, true ) ) { 1531 1531 $data['featured_media'] = (int) get_post_thumbnail_id( $post->ID ); 1532 1532 } 1533 1533 1534 if ( ! empty( $schema['properties']['parent']) ) {1534 if ( in_array( 'parent', $fields, true ) ) { 1535 1535 $data['parent'] = (int) $post->post_parent; 1536 1536 } 1537 1537 1538 if ( ! empty( $schema['properties']['menu_order']) ) {1538 if ( in_array( 'menu_order', $fields, true ) ) { 1539 1539 $data['menu_order'] = (int) $post->menu_order; 1540 1540 } 1541 1541 1542 if ( ! empty( $schema['properties']['comment_status']) ) {1542 if ( in_array( 'comment_status', $fields, true ) ) { 1543 1543 $data['comment_status'] = $post->comment_status; 1544 1544 } 1545 1545 1546 if ( ! empty( $schema['properties']['ping_status']) ) {1546 if ( in_array( 'ping_status', $fields, true ) ) { 1547 1547 $data['ping_status'] = $post->ping_status; 1548 1548 } 1549 1549 1550 if ( ! empty( $schema['properties']['sticky']) ) {1550 if ( in_array( 'sticky', $fields, true ) ) { 1551 1551 $data['sticky'] = is_sticky( $post->ID ); 1552 1552 } 1553 1553 1554 if ( ! empty( $schema['properties']['template']) ) {1554 if ( in_array( 'template', $fields, true ) ) { 1555 1555 if ( $template = get_page_template_slug( $post->ID ) ) { 1556 1556 $data['template'] = $template; … … 1560 1560 } 1561 1561 1562 if ( ! empty( $schema['properties']['format']) ) {1562 if ( in_array( 'format', $fields, true ) ) { 1563 1563 $data['format'] = get_post_format( $post->ID ); 1564 1564 … … 1569 1569 } 1570 1570 1571 if ( ! empty( $schema['properties']['meta']) ) {1571 if ( in_array( 'meta', $fields, true ) ) { 1572 1572 $data['meta'] = $this->meta->get_value( $post->ID, $request ); 1573 1573 } … … 1578 1578 $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; 1579 1579 1580 if ( ! empty( $schema['properties'][ $base ]) ) {1580 if ( in_array( $base, $fields, true ) ) { 1581 1581 $terms = get_the_terms( $post, $taxonomy->name ); 1582 1582 $data[ $base ] = $terms ? array_values( wp_list_pluck( $terms, 'term_id' ) ) : array();
Note: See TracChangeset
for help on using the changeset viewer.