Plugin Directory

Changeset 1392536


Ignore:
Timestamp:
04/11/2016 11:45:29 PM (10 years ago)
Author:
KCPT
Message:

Bug fix - updated to 1.2

Location:
rest-api-search/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • rest-api-search/trunk/lib/class-wp-rest-search-controller.php

    r1392300 r1392536  
    88    private static $instance;
    99
    10     private        $namespace             = 'wp/v2';
     10    protected      $namespace             = 'wp/v2';
    1111
    1212    private        $base                  = 'search';
     
    3535    }
    3636
    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 (
    4142            '$schema'    => 'http://json-schema.org/draft-04/schema#',
    4243            'title'      => $this->post_type,
     
    4546             * Base properties for every Post.
    4647             */
    47             'properties' => array(
    48                 'date'            => array(
     48            'properties' => array (
     49                'date'         => array (
    4950                    'description' => "The date the object was published, in the site's timezone.",
    5051                    'type'        => 'string',
    5152                    '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 (
    5556                    'description' => 'The date the object was published, as GMT.',
    5657                    'type'        => 'string',
    5758                    'format'      => 'date-time',
    58                     'context'     => array( 'view', 'edit' ),
    59                 ),
    60                 'guid'            => array(
     59                    'context'     => array ( 'view', 'edit' ),
     60                ),
     61                'guid'         => array (
    6162                    'description' => 'The globally unique identifier for the object.',
    6263                    'type'        => 'object',
    63                     'context'     => array( 'view', 'edit' ),
     64                    'context'     => array ( 'view', 'edit' ),
    6465                    'readonly'    => true,
    65                     'properties'  => array(
    66                         'raw'      => array(
     66                    'properties'  => array (
     67                        'raw'      => array (
    6768                            'description' => 'GUID for the object, as it exists in the database.',
    6869                            'type'        => 'string',
    69                             'context'     => array( 'edit' ),
     70                            'context'     => array ( 'edit' ),
    7071                        ),
    71                         'rendered' => array(
     72                        'rendered' => array (
    7273                            'description' => 'GUID for the object, transformed for display.',
    7374                            'type'        => 'string',
    74                             'context'     => array( 'view', 'edit' ),
     75                            'context'     => array ( 'view', 'edit' ),
    7576                        ),
    7677                    ),
    7778                ),
    78                 'id'              => array(
     79                'id'           => array (
    7980                    'description' => 'Unique identifier for the object.',
    8081                    'type'        => 'integer',
    81                     'context'     => array( 'view', 'edit', 'embed' ),
     82                    'context'     => array ( 'view', 'edit', 'embed' ),
    8283                    'readonly'    => true,
    8384                ),
    84                 'link'            => array(
     85                'link'         => array (
    8586                    'description' => 'URL to the object.',
    8687                    'type'        => 'string',
    8788                    'format'      => 'uri',
    88                     'context'     => array( 'view', 'edit', 'embed' ),
     89                    'context'     => array ( 'view', 'edit', 'embed' ),
    8990                    'readonly'    => true,
    9091                ),
    91                 'modified'        => array(
     92                'modified'     => array (
    9293                    'description' => "The date the object was last modified, in the site's timezone.",
    9394                    'type'        => 'string',
    9495                    'format'      => 'date-time',
    95                     'context'     => array( 'view', 'edit' ),
    96                 ),
    97                 'modified_gmt'    => array(
     96                    'context'     => array ( 'view', 'edit' ),
     97                ),
     98                'modified_gmt' => array (
    9899                    'description' => 'The date the object was last modified, as GMT.',
    99100                    'type'        => 'string',
    100101                    'format'      => 'date-time',
    101                     'context'     => array( 'view', 'edit' ),
    102                 ),
    103                 'password'        => array(
     102                    'context'     => array ( 'view', 'edit' ),
     103                ),
     104                'password'     => array (
    104105                    'description' => 'A password to protect access to the post.',
    105106                    'type'        => 'string',
    106                     'context'     => array( 'edit' ),
    107                 ),
    108                 'slug'            => array(
     107                    'context'     => array ( 'edit' ),
     108                ),
     109                'slug'         => array (
    109110                    'description' => 'An alphanumeric identifier for the object unique to its type.',
    110111                    'type'        => 'string',
    111                     'context'     => array( 'view', 'edit', 'embed' ),
    112                     'arg_options' => array(
     112                    'context'     => array ( 'view', 'edit', 'embed' ),
     113                    'arg_options' => array (
    113114                        'sanitize_callback' => 'sanitize_title',
    114115                    ),
    115116                ),
    116                 'status'          => array(
     117                'status'       => array (
    117118                    'description' => 'A named status for the object.',
    118119                    '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 (
    123124                    'description' => 'Type of Post for the object.',
    124125                    'type'        => 'string',
    125                     'context'     => array( 'view', 'edit', 'embed' ),
     126                    'context'     => array ( 'view', 'edit', 'embed' ),
    126127                    'readonly'    => true,
    127128                ),
     
    129130        );
    130131
    131         $post_type_obj = get_post_type_object( $this->post_type );
     132        $post_type_obj = get_post_type_object ( $this->post_type );
    132133        if ( $post_type_obj->hierarchical ) {
    133             $schema['properties']['parent'] = array(
     134            $schema[ 'properties' ][ 'parent' ] = array (
    134135                'description' => 'The ID for the parent of the object.',
    135136                'type'        => 'integer',
    136                 'context'     => array( 'view', 'edit' ),
     137                'context'     => array ( 'view', 'edit' ),
    137138            );
    138139        }
    139140
    140         $post_type_attributes = array(
     141        $post_type_attributes = array (
    141142            'title',
    142143            'editor',
     
    149150            'post-formats',
    150151        );
    151         $fixed_schemas = array(
    152             'post' => array(
     152        $fixed_schemas        = array (
     153            'post'       => array (
    153154                'title',
    154155                'editor',
     
    160161                'post-formats',
    161162            ),
    162             'page' => array(
     163            'page'       => array (
    163164                'title',
    164165                'editor',
     
    170171                'page-attributes',
    171172            ),
    172             'attachment' => array(
     173            'attachment' => array (
    173174                'title',
    174175                'author',
     
    178179        );
    179180        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            ) {
    181184                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            ) {
    183188                continue;
    184189            }
     
    187192
    188193                case 'title':
    189                     $schema['properties']['title'] = array(
     194                    $schema[ 'properties' ][ 'title' ] = array (
    190195                        'description' => 'The title for the object.',
    191196                        '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 (
    195200                                'description' => 'Title for the object, as it exists in the database.',
    196201                                'type'        => 'string',
    197                                 'context'     => array( 'edit' ),
     202                                'context'     => array ( 'edit' ),
    198203                            ),
    199                             'rendered' => array(
     204                            'rendered' => array (
    200205                                'description' => 'Title for the object, transformed for display.',
    201206                                'type'        => 'string',
    202                                 'context'     => array( 'view', 'edit', 'embed' ),
     207                                'context'     => array ( 'view', 'edit', 'embed' ),
    203208                            ),
    204209                        ),
     
    207212
    208213                case 'editor':
    209                     $schema['properties']['content'] = array(
     214                    $schema[ 'properties' ][ 'content' ] = array (
    210215                        'description' => 'The content for the object.',
    211216                        'type'        => 'object',
    212                         'context'     => array( 'view', 'edit' ),
    213                         'properties'  => array(
    214                             'raw' => array(
     217                        'context'     => array ( 'view', 'edit' ),
     218                        'properties'  => array (
     219                            'raw'      => array (
    215220                                'description' => 'Content for the object, as it exists in the database.',
    216221                                'type'        => 'string',
    217                                 'context'     => array( 'edit' ),
     222                                'context'     => array ( 'edit' ),
    218223                            ),
    219                             'rendered' => array(
     224                            'rendered' => array (
    220225                                'description' => 'Content for the object, transformed for display.',
    221226                                'type'        => 'string',
    222                                 'context'     => array( 'view', 'edit' ),
     227                                'context'     => array ( 'view', 'edit' ),
    223228                            ),
    224229                        ),
     
    227232
    228233                case 'author':
    229                     $schema['properties']['author'] = array(
     234                    $schema[ 'properties' ][ 'author' ] = array (
    230235                        'description' => 'The ID for the author of the object.',
    231236                        'type'        => 'integer',
    232                         'context'     => array( 'view', 'edit', 'embed' ),
     237                        'context'     => array ( 'view', 'edit', 'embed' ),
    233238                    );
    234239                    break;
    235240
    236241                case 'excerpt':
    237                     $schema['properties']['excerpt'] = array(
     242                    $schema[ 'properties' ][ 'excerpt' ] = array (
    238243                        'description' => 'The excerpt for the object.',
    239244                        '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 (
    243248                                'description' => 'Excerpt for the object, as it exists in the database.',
    244249                                'type'        => 'string',
    245                                 'context'     => array( 'edit' ),
     250                                'context'     => array ( 'edit' ),
    246251                            ),
    247                             'rendered' => array(
     252                            'rendered' => array (
    248253                                'description' => 'Excerpt for the object, transformed for display.',
    249254                                'type'        => 'string',
    250                                 'context'     => array( 'view', 'edit', 'embed' ),
     255                                'context'     => array ( 'view', 'edit', 'embed' ),
    251256                            ),
    252257                        ),
     
    255260
    256261                case 'thumbnail':
    257                     $schema['properties']['featured_image'] = array(
     262                    $schema[ 'properties' ][ 'featured_image' ] = array (
    258263                        'description' => 'ID of the featured image for the object.',
    259264                        'type'        => 'integer',
    260                         'context'     => array( 'view', 'edit' ),
     265                        'context'     => array ( 'view', 'edit' ),
    261266                    );
    262267                    break;
    263268
    264269                case 'comments':
    265                     $schema['properties']['comment_status'] = array(
     270                    $schema[ 'properties' ][ 'comment_status' ] = array (
    266271                        'description' => 'Whether or not comments are open on the object.',
    267272                        '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 (
    272277                        'description' => 'Whether or not the object can be pinged.',
    273278                        'type'        => 'string',
    274                         'enum'        => array( 'open', 'closed' ),
    275                         'context'     => array( 'view', 'edit' ),
     279                        'enum'        => array ( 'open', 'closed' ),
     280                        'context'     => array ( 'view', 'edit' ),
    276281                    );
    277282                    break;
    278283
    279284                case 'page-attributes':
    280                     $schema['properties']['menu_order'] = array(
     285                    $schema[ 'properties' ][ 'menu_order' ] = array (
    281286                        'description' => 'The order of the object in relation to other object of its type.',
    282287                        'type'        => 'integer',
    283                         'context'     => array( 'view', 'edit' ),
     288                        'context'     => array ( 'view', 'edit' ),
    284289                    );
    285290                    break;
    286291
    287292                case 'post-formats':
    288                     $schema['properties']['format'] = array(
     293                    $schema[ 'properties' ][ 'format' ] = array (
    289294                        'description' => 'The format for the object.',
    290295                        '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' ),
    293298                    );
    294299                    break;
     
    298303
    299304        if ( 'post' === $this->post_type ) {
    300             $schema['properties']['sticky'] = array(
     305            $schema[ 'properties' ][ 'sticky' ] = array (
    301306                'description' => 'Whether or not the object should be treated as sticky.',
    302307                'type'        => 'boolean',
    303                 'context'     => array( 'view', 'edit' ),
     308                'context'     => array ( 'view', 'edit' ),
    304309            );
    305310        }
    306311
    307312        if ( 'page' === $this->post_type ) {
    308             $schema['properties']['template'] = array(
     313            $schema[ 'properties' ][ 'template' ] = array (
    309314                'description' => 'The theme file to use to display the object.',
    310315                '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' ),
    313318            );
    314319        }
    315320
    316         return $this->add_additional_fields_schema( $schema );
     321        return $this->add_additional_fields_schema ( $schema );
    317322    }
    318323
     
    337342
    338343        $items = $query->query ( array (
    339             'paged'           => $page,
     344            'paged'          => $page,
    340345            'post_type'      => 'any',
    341346            'posts_per_page' => 10,
     
    379384    }
    380385
    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.' );
    384391        }
    385392
    386393        /** 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 ) );
    388395
    389396        if ( empty( $excerpt ) ) {
  • rest-api-search/trunk/readme.txt

    r1392300 r1392536  
    55Requires at least: 4.4
    66Tested up to: 4.4.2
    7 Stable tag: 1.1
     7Stable tag: 1.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7171= 1.1 =
    7272* 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  
    44Plugin URI:  https://github.com/KCPT19/REST-API-Search
    55Description: Adds in the missing search functionality of all post types to the REST API v2 plugin.
    6 Version:     1.1
     6Version:     1.2
    77Author:      KCPT
    88Author URI:  https://github.com/orgs/KCPT19
Note: See TracChangeset for help on using the changeset viewer.