diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index ffac007c82..2d582948db 100644
|
|
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1125 | 1125 | $prepared_post->page_template = null; |
1126 | 1126 | } |
1127 | 1127 | |
| 1128 | foreach ( array( 'to_ping', 'pinged' ) as $trackback_attribute ) { |
| 1129 | if ( ! empty( $schema['properties'][ $trackback_attribute ] ) && isset( $request[ $trackback_attribute ] ) ) { |
| 1130 | if ( $request[ $trackback_attribute ] ) { |
| 1131 | $trackback_urls = (array) $request[ $trackback_attribute ]; |
| 1132 | $prepared_post->{ $trackback_attribute } = implode( ' ', $trackback_urls ); |
| 1133 | } else { |
| 1134 | $prepared_post->{ $trackback_attribute } = ''; |
| 1135 | } |
| 1136 | } |
| 1137 | } |
| 1138 | |
1128 | 1139 | /** |
1129 | 1140 | * Filters a post before it is inserted via the REST API. |
1130 | 1141 | * |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1625 | 1636 | } |
1626 | 1637 | } |
1627 | 1638 | |
| 1639 | foreach ( array( 'to_ping', 'pinged' ) as $trackback_attribute ) { |
| 1640 | if ( rest_is_field_included( $trackback_attribute, $fields ) ) { |
| 1641 | $trackback_urls = trim( $post->{$trackback_attribute}, "\n" ); |
| 1642 | |
| 1643 | if ( $trackback_urls ) { |
| 1644 | $data[ $trackback_attribute ] = explode( "\n", $trackback_urls ); |
| 1645 | } else { |
| 1646 | $data[ $trackback_attribute ] = array(); |
| 1647 | } |
| 1648 | } |
| 1649 | } |
| 1650 | |
1628 | 1651 | if ( rest_is_field_included( 'meta', $fields ) ) { |
1629 | 1652 | $data['meta'] = $this->meta->get_value( $post->ID, $request ); |
1630 | 1653 | } |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2030 | 2053 | 'revisions', |
2031 | 2054 | 'page-attributes', |
2032 | 2055 | 'post-formats', |
| 2056 | 'trackbacks', |
2033 | 2057 | 'custom-fields', |
2034 | 2058 | ); |
2035 | 2059 | $fixed_schemas = array( |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2042 | 2066 | 'comments', |
2043 | 2067 | 'revisions', |
2044 | 2068 | 'post-formats', |
| 2069 | 'trackbacks', |
2045 | 2070 | 'custom-fields', |
2046 | 2071 | ), |
2047 | 2072 | 'page' => array( |
… |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2216 | 2241 | ); |
2217 | 2242 | break; |
2218 | 2243 | |
| 2244 | case 'trackbacks': |
| 2245 | $trackback_props_attrs = array( |
| 2246 | 'type' => 'array', |
| 2247 | 'items' => array( |
| 2248 | 'type' => 'string', |
| 2249 | 'format' => 'uri', |
| 2250 | ), |
| 2251 | 'default' => array(), |
| 2252 | 'context' => array( 'edit' ), |
| 2253 | 'arg_options' => array( |
| 2254 | 'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database() |
| 2255 | 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database() |
| 2256 | ), |
| 2257 | ); |
| 2258 | |
| 2259 | $schema['properties']['to_ping'] = array_merge( |
| 2260 | array( |
| 2261 | 'description' => __( 'List of the trackbacks to send.' ), |
| 2262 | ), |
| 2263 | $trackback_props_attrs |
| 2264 | ); |
| 2265 | |
| 2266 | $schema['properties']['pinged'] = array_merge( |
| 2267 | array( |
| 2268 | 'description' => __( 'List of the trackbacks sent.' ), |
| 2269 | ), |
| 2270 | $trackback_props_attrs |
| 2271 | ); |
| 2272 | break; |
| 2273 | |
2219 | 2274 | case 'custom-fields': |
2220 | 2275 | $schema['properties']['meta'] = $this->meta->get_field_schema(); |
2221 | 2276 | break; |
diff --git tests/phpunit/tests/rest-api/rest-posts-controller.php tests/phpunit/tests/rest-api/rest-posts-controller.php
index da6c0ada98..af99baa7c7 100644
|
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
3889 | 3889 | $response = rest_get_server()->dispatch( $request ); |
3890 | 3890 | $data = $response->get_data(); |
3891 | 3891 | $properties = $data['schema']['properties']; |
3892 | | $this->assertEquals( 26, count( $properties ) ); |
| 3892 | $this->assertEquals( 28, count( $properties ) ); |
3893 | 3893 | $this->assertArrayHasKey( 'author', $properties ); |
3894 | 3894 | $this->assertArrayHasKey( 'comment_status', $properties ); |
3895 | 3895 | $this->assertArrayHasKey( 'content', $properties ); |
… |
… |
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
3908 | 3908 | $this->assertArrayHasKey( 'password', $properties ); |
3909 | 3909 | $this->assertArrayHasKey( 'permalink_template', $properties ); |
3910 | 3910 | $this->assertArrayHasKey( 'ping_status', $properties ); |
| 3911 | $this->assertArrayHasKey( 'pinged', $properties ); |
3911 | 3912 | $this->assertArrayHasKey( 'slug', $properties ); |
3912 | 3913 | $this->assertArrayHasKey( 'status', $properties ); |
3913 | 3914 | $this->assertArrayHasKey( 'sticky', $properties ); |
3914 | 3915 | $this->assertArrayHasKey( 'template', $properties ); |
3915 | 3916 | $this->assertArrayHasKey( 'title', $properties ); |
| 3917 | $this->assertArrayHasKey( 'to_ping', $properties ); |
3916 | 3918 | $this->assertArrayHasKey( 'type', $properties ); |
3917 | 3919 | $this->assertArrayHasKey( 'tags', $properties ); |
3918 | 3920 | $this->assertArrayHasKey( 'categories', $properties ); |
… |
… |
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
4000 | 4002 | 'password', |
4001 | 4003 | 'permalink_template', |
4002 | 4004 | 'ping_status', |
| 4005 | 'pinged', |
4003 | 4006 | 'slug', |
4004 | 4007 | 'status', |
4005 | 4008 | 'sticky', |
4006 | 4009 | 'tags', |
4007 | 4010 | 'template', |
4008 | 4011 | 'title', |
| 4012 | 'to_ping', |
4009 | 4013 | 'type', |
4010 | 4014 | ); |
4011 | 4015 | |
diff --git tests/qunit/fixtures/wp-api-generated.js tests/qunit/fixtures/wp-api-generated.js
index 9c130539b7..3833904b2a 100644
|
|
mockedApiResponse.Schema = { |
477 | 477 | "description": "The format for the object.", |
478 | 478 | "type": "string" |
479 | 479 | }, |
| 480 | "to_ping": { |
| 481 | "required": false, |
| 482 | "default": [], |
| 483 | "description": "List of the trackbacks to send.", |
| 484 | "type": "array", |
| 485 | "items": { |
| 486 | "type": "string", |
| 487 | "format": "uri" |
| 488 | } |
| 489 | }, |
| 490 | "pinged": { |
| 491 | "required": false, |
| 492 | "default": [], |
| 493 | "description": "List of the trackbacks sent.", |
| 494 | "type": "array", |
| 495 | "items": { |
| 496 | "type": "string", |
| 497 | "format": "uri" |
| 498 | } |
| 499 | }, |
480 | 500 | "meta": { |
481 | 501 | "required": false, |
482 | 502 | "description": "Meta fields.", |
… |
… |
mockedApiResponse.Schema = { |
663 | 683 | "description": "The format for the object.", |
664 | 684 | "type": "string" |
665 | 685 | }, |
| 686 | "to_ping": { |
| 687 | "required": false, |
| 688 | "description": "List of the trackbacks to send.", |
| 689 | "type": "array", |
| 690 | "items": { |
| 691 | "type": "string", |
| 692 | "format": "uri" |
| 693 | } |
| 694 | }, |
| 695 | "pinged": { |
| 696 | "required": false, |
| 697 | "description": "List of the trackbacks sent.", |
| 698 | "type": "array", |
| 699 | "items": { |
| 700 | "type": "string", |
| 701 | "format": "uri" |
| 702 | } |
| 703 | }, |
666 | 704 | "meta": { |
667 | 705 | "required": false, |
668 | 706 | "description": "Meta fields.", |
… |
… |
mockedApiResponse.Schema = { |
1009 | 1047 | "description": "The format for the object.", |
1010 | 1048 | "type": "string" |
1011 | 1049 | }, |
| 1050 | "to_ping": { |
| 1051 | "required": false, |
| 1052 | "description": "List of the trackbacks to send.", |
| 1053 | "type": "array", |
| 1054 | "items": { |
| 1055 | "type": "string", |
| 1056 | "format": "uri" |
| 1057 | } |
| 1058 | }, |
| 1059 | "pinged": { |
| 1060 | "required": false, |
| 1061 | "description": "List of the trackbacks sent.", |
| 1062 | "type": "array", |
| 1063 | "items": { |
| 1064 | "type": "string", |
| 1065 | "format": "uri" |
| 1066 | } |
| 1067 | }, |
1012 | 1068 | "meta": { |
1013 | 1069 | "required": false, |
1014 | 1070 | "description": "Meta fields.", |