Changeset 1392536
- Timestamp:
- 04/11/2016 11:45:29 PM (10 years ago)
- Location:
- rest-api-search/trunk
- Files:
-
- 3 edited
-
lib/class-wp-rest-search-controller.php (modified) (15 diffs)
-
readme.txt (modified) (2 diffs)
-
rest-api-search.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
rest-api-search/trunk/lib/class-wp-rest-search-controller.php
r1392300 r1392536 8 8 private static $instance; 9 9 10 pr ivate$namespace = 'wp/v2';10 protected $namespace = 'wp/v2'; 11 11 12 12 private $base = 'search'; … … 35 35 } 36 36 37 public function get_item_schema() { 38 39 $base = $this->get_post_type_base( $this->post_type ); 40 $schema = array( 37 public function get_item_schema () 38 { 39 40 $base = $this->get_post_type_base ( $this->post_type ); 41 $schema = array ( 41 42 '$schema' => 'http://json-schema.org/draft-04/schema#', 42 43 'title' => $this->post_type, … … 45 46 * Base properties for every Post. 46 47 */ 47 'properties' => array (48 'date' => array(48 'properties' => array ( 49 'date' => array ( 49 50 'description' => "The date the object was published, in the site's timezone.", 50 51 'type' => 'string', 51 52 'format' => 'date-time', 52 'context' => array ( 'view', 'edit', 'embed' ),53 ), 54 'date_gmt' => array(53 'context' => array ( 'view', 'edit', 'embed' ), 54 ), 55 'date_gmt' => array ( 55 56 'description' => 'The date the object was published, as GMT.', 56 57 'type' => 'string', 57 58 'format' => 'date-time', 58 'context' => array ( 'view', 'edit' ),59 ), 60 'guid' => array(59 'context' => array ( 'view', 'edit' ), 60 ), 61 'guid' => array ( 61 62 'description' => 'The globally unique identifier for the object.', 62 63 'type' => 'object', 63 'context' => array ( 'view', 'edit' ),64 'context' => array ( 'view', 'edit' ), 64 65 'readonly' => true, 65 'properties' => array (66 'raw' => array (66 'properties' => array ( 67 'raw' => array ( 67 68 'description' => 'GUID for the object, as it exists in the database.', 68 69 'type' => 'string', 69 'context' => array ( 'edit' ),70 'context' => array ( 'edit' ), 70 71 ), 71 'rendered' => array (72 'rendered' => array ( 72 73 'description' => 'GUID for the object, transformed for display.', 73 74 'type' => 'string', 74 'context' => array ( 'view', 'edit' ),75 'context' => array ( 'view', 'edit' ), 75 76 ), 76 77 ), 77 78 ), 78 'id' => array(79 'id' => array ( 79 80 'description' => 'Unique identifier for the object.', 80 81 'type' => 'integer', 81 'context' => array ( 'view', 'edit', 'embed' ),82 'context' => array ( 'view', 'edit', 'embed' ), 82 83 'readonly' => true, 83 84 ), 84 'link' => array(85 'link' => array ( 85 86 'description' => 'URL to the object.', 86 87 'type' => 'string', 87 88 'format' => 'uri', 88 'context' => array ( 'view', 'edit', 'embed' ),89 'context' => array ( 'view', 'edit', 'embed' ), 89 90 'readonly' => true, 90 91 ), 91 'modified' => array(92 'modified' => array ( 92 93 'description' => "The date the object was last modified, in the site's timezone.", 93 94 'type' => 'string', 94 95 'format' => 'date-time', 95 'context' => array ( 'view', 'edit' ),96 ), 97 'modified_gmt' => array(96 'context' => array ( 'view', 'edit' ), 97 ), 98 'modified_gmt' => array ( 98 99 'description' => 'The date the object was last modified, as GMT.', 99 100 'type' => 'string', 100 101 'format' => 'date-time', 101 'context' => array ( 'view', 'edit' ),102 ), 103 'password' => array(102 'context' => array ( 'view', 'edit' ), 103 ), 104 'password' => array ( 104 105 'description' => 'A password to protect access to the post.', 105 106 'type' => 'string', 106 'context' => array ( 'edit' ),107 ), 108 'slug' => array(107 'context' => array ( 'edit' ), 108 ), 109 'slug' => array ( 109 110 'description' => 'An alphanumeric identifier for the object unique to its type.', 110 111 'type' => 'string', 111 'context' => array ( 'view', 'edit', 'embed' ),112 'arg_options' => array (112 'context' => array ( 'view', 'edit', 'embed' ), 113 'arg_options' => array ( 113 114 'sanitize_callback' => 'sanitize_title', 114 115 ), 115 116 ), 116 'status' => array(117 'status' => array ( 117 118 'description' => 'A named status for the object.', 118 119 'type' => 'string', 119 'enum' => array_keys ( get_post_stati( array( 'internal' => false ) ) ),120 'context' => array ( 'edit' ),121 ), 122 'type' => array(120 'enum' => array_keys ( get_post_stati ( array ( 'internal' => false ) ) ), 121 'context' => array ( 'edit' ), 122 ), 123 'type' => array ( 123 124 'description' => 'Type of Post for the object.', 124 125 'type' => 'string', 125 'context' => array ( 'view', 'edit', 'embed' ),126 'context' => array ( 'view', 'edit', 'embed' ), 126 127 'readonly' => true, 127 128 ), … … 129 130 ); 130 131 131 $post_type_obj = get_post_type_object ( $this->post_type );132 $post_type_obj = get_post_type_object ( $this->post_type ); 132 133 if ( $post_type_obj->hierarchical ) { 133 $schema[ 'properties']['parent'] = array(134 $schema[ 'properties' ][ 'parent' ] = array ( 134 135 'description' => 'The ID for the parent of the object.', 135 136 'type' => 'integer', 136 'context' => array ( 'view', 'edit' ),137 'context' => array ( 'view', 'edit' ), 137 138 ); 138 139 } 139 140 140 $post_type_attributes = array (141 $post_type_attributes = array ( 141 142 'title', 142 143 'editor', … … 149 150 'post-formats', 150 151 ); 151 $fixed_schemas = array(152 'post' => array(152 $fixed_schemas = array ( 153 'post' => array ( 153 154 'title', 154 155 'editor', … … 160 161 'post-formats', 161 162 ), 162 'page' => array(163 'page' => array ( 163 164 'title', 164 165 'editor', … … 170 171 'page-attributes', 171 172 ), 172 'attachment' => array (173 'attachment' => array ( 173 174 'title', 174 175 'author', … … 178 179 ); 179 180 foreach ( $post_type_attributes as $attribute ) { 180 if ( isset( $fixed_schemas[ $this->post_type ] ) && ! in_array( $attribute, $fixed_schemas[ $this->post_type ] ) ) { 181 if ( isset( $fixed_schemas[ $this->post_type ] ) && ! in_array ( $attribute, 182 $fixed_schemas[ $this->post_type ] ) 183 ) { 181 184 continue; 182 } elseif ( ! in_array( $this->post_type, array_keys( $fixed_schemas ) ) && ! post_type_supports( $this->post_type, $attribute ) ) { 185 } elseif ( ! in_array ( $this->post_type, 186 array_keys ( $fixed_schemas ) ) && ! post_type_supports ( $this->post_type, $attribute ) 187 ) { 183 188 continue; 184 189 } … … 187 192 188 193 case 'title': 189 $schema[ 'properties']['title'] = array(194 $schema[ 'properties' ][ 'title' ] = array ( 190 195 'description' => 'The title for the object.', 191 196 'type' => 'object', 192 'context' => array ( 'view', 'edit', 'embed' ),193 'properties' => array (194 'raw' => array(197 'context' => array ( 'view', 'edit', 'embed' ), 198 'properties' => array ( 199 'raw' => array ( 195 200 'description' => 'Title for the object, as it exists in the database.', 196 201 'type' => 'string', 197 'context' => array ( 'edit' ),202 'context' => array ( 'edit' ), 198 203 ), 199 'rendered' => array (204 'rendered' => array ( 200 205 'description' => 'Title for the object, transformed for display.', 201 206 'type' => 'string', 202 'context' => array ( 'view', 'edit', 'embed' ),207 'context' => array ( 'view', 'edit', 'embed' ), 203 208 ), 204 209 ), … … 207 212 208 213 case 'editor': 209 $schema[ 'properties']['content'] = array(214 $schema[ 'properties' ][ 'content' ] = array ( 210 215 'description' => 'The content for the object.', 211 216 'type' => 'object', 212 'context' => array ( 'view', 'edit' ),213 'properties' => array (214 'raw' => array(217 'context' => array ( 'view', 'edit' ), 218 'properties' => array ( 219 'raw' => array ( 215 220 'description' => 'Content for the object, as it exists in the database.', 216 221 'type' => 'string', 217 'context' => array ( 'edit' ),222 'context' => array ( 'edit' ), 218 223 ), 219 'rendered' => array (224 'rendered' => array ( 220 225 'description' => 'Content for the object, transformed for display.', 221 226 'type' => 'string', 222 'context' => array ( 'view', 'edit' ),227 'context' => array ( 'view', 'edit' ), 223 228 ), 224 229 ), … … 227 232 228 233 case 'author': 229 $schema[ 'properties']['author'] = array(234 $schema[ 'properties' ][ 'author' ] = array ( 230 235 'description' => 'The ID for the author of the object.', 231 236 'type' => 'integer', 232 'context' => array ( 'view', 'edit', 'embed' ),237 'context' => array ( 'view', 'edit', 'embed' ), 233 238 ); 234 239 break; 235 240 236 241 case 'excerpt': 237 $schema[ 'properties']['excerpt'] = array(242 $schema[ 'properties' ][ 'excerpt' ] = array ( 238 243 'description' => 'The excerpt for the object.', 239 244 'type' => 'object', 240 'context' => array ( 'view', 'edit', 'embed' ),241 'properties' => array (242 'raw' => array(245 'context' => array ( 'view', 'edit', 'embed' ), 246 'properties' => array ( 247 'raw' => array ( 243 248 'description' => 'Excerpt for the object, as it exists in the database.', 244 249 'type' => 'string', 245 'context' => array ( 'edit' ),250 'context' => array ( 'edit' ), 246 251 ), 247 'rendered' => array (252 'rendered' => array ( 248 253 'description' => 'Excerpt for the object, transformed for display.', 249 254 'type' => 'string', 250 'context' => array ( 'view', 'edit', 'embed' ),255 'context' => array ( 'view', 'edit', 'embed' ), 251 256 ), 252 257 ), … … 255 260 256 261 case 'thumbnail': 257 $schema[ 'properties']['featured_image'] = array(262 $schema[ 'properties' ][ 'featured_image' ] = array ( 258 263 'description' => 'ID of the featured image for the object.', 259 264 'type' => 'integer', 260 'context' => array ( 'view', 'edit' ),265 'context' => array ( 'view', 'edit' ), 261 266 ); 262 267 break; 263 268 264 269 case 'comments': 265 $schema[ 'properties']['comment_status'] = array(270 $schema[ 'properties' ][ 'comment_status' ] = array ( 266 271 'description' => 'Whether or not comments are open on the object.', 267 272 'type' => 'string', 268 'enum' => array ( 'open', 'closed' ),269 'context' => array ( 'view', 'edit' ),270 ); 271 $schema[ 'properties']['ping_status'] = array(273 'enum' => array ( 'open', 'closed' ), 274 'context' => array ( 'view', 'edit' ), 275 ); 276 $schema[ 'properties' ][ 'ping_status' ] = array ( 272 277 'description' => 'Whether or not the object can be pinged.', 273 278 'type' => 'string', 274 'enum' => array ( 'open', 'closed' ),275 'context' => array ( 'view', 'edit' ),279 'enum' => array ( 'open', 'closed' ), 280 'context' => array ( 'view', 'edit' ), 276 281 ); 277 282 break; 278 283 279 284 case 'page-attributes': 280 $schema[ 'properties']['menu_order'] = array(285 $schema[ 'properties' ][ 'menu_order' ] = array ( 281 286 'description' => 'The order of the object in relation to other object of its type.', 282 287 'type' => 'integer', 283 'context' => array ( 'view', 'edit' ),288 'context' => array ( 'view', 'edit' ), 284 289 ); 285 290 break; 286 291 287 292 case 'post-formats': 288 $schema[ 'properties']['format'] = array(293 $schema[ 'properties' ][ 'format' ] = array ( 289 294 'description' => 'The format for the object.', 290 295 'type' => 'string', 291 'enum' => array_values ( get_post_format_slugs() ),292 'context' => array ( 'view', 'edit' ),296 'enum' => array_values ( get_post_format_slugs () ), 297 'context' => array ( 'view', 'edit' ), 293 298 ); 294 299 break; … … 298 303 299 304 if ( 'post' === $this->post_type ) { 300 $schema[ 'properties']['sticky'] = array(305 $schema[ 'properties' ][ 'sticky' ] = array ( 301 306 'description' => 'Whether or not the object should be treated as sticky.', 302 307 'type' => 'boolean', 303 'context' => array ( 'view', 'edit' ),308 'context' => array ( 'view', 'edit' ), 304 309 ); 305 310 } 306 311 307 312 if ( 'page' === $this->post_type ) { 308 $schema[ 'properties']['template'] = array(313 $schema[ 'properties' ][ 'template' ] = array ( 309 314 'description' => 'The theme file to use to display the object.', 310 315 'type' => 'string', 311 'enum' => array_keys ( wp_get_theme()->get_page_templates() ),312 'context' => array ( 'view', 'edit' ),316 'enum' => array_keys ( wp_get_theme ()->get_page_templates () ), 317 'context' => array ( 'view', 'edit' ), 313 318 ); 314 319 } 315 320 316 return $this->add_additional_fields_schema ( $schema );321 return $this->add_additional_fields_schema ( $schema ); 317 322 } 318 323 … … 337 342 338 343 $items = $query->query ( array ( 339 'paged' => $page,344 'paged' => $page, 340 345 'post_type' => 'any', 341 346 'posts_per_page' => 10, … … 379 384 } 380 385 381 protected function prepare_excerpt_response( $excerpt ) { 382 if ( post_password_required() ) { 383 return __( 'There is no excerpt because this is a protected post.' ); 386 protected function prepare_excerpt_response ( $excerpt ) 387 { 388 389 if ( post_password_required () ) { 390 return __ ( 'There is no excerpt because this is a protected post.' ); 384 391 } 385 392 386 393 /** This filter is documented in wp-includes/post-template.php */ 387 $excerpt = apply_filters ( 'the_excerpt', apply_filters( 'get_the_excerpt', $excerpt ) );394 $excerpt = apply_filters ( 'the_excerpt', apply_filters ( 'get_the_excerpt', $excerpt ) ); 388 395 389 396 if ( empty( $excerpt ) ) { -
rest-api-search/trunk/readme.txt
r1392300 r1392536 5 5 Requires at least: 4.4 6 6 Tested up to: 4.4.2 7 Stable tag: 1. 17 Stable tag: 1.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 71 71 = 1.1 = 72 72 * Restructured code to allow for custom fields added in by other plugins 73 74 = 1.2 = 75 * Bug Fix - namespace variable of class needs to be protected. -
rest-api-search/trunk/rest-api-search.php
r1392300 r1392536 4 4 Plugin URI: https://github.com/KCPT19/REST-API-Search 5 5 Description: Adds in the missing search functionality of all post types to the REST API v2 plugin. 6 Version: 1. 16 Version: 1.2 7 7 Author: KCPT 8 8 Author URI: https://github.com/orgs/KCPT19
Note: See TracChangeset
for help on using the changeset viewer.