| @@ -22,9 +22,12 @@ | ||
| 22 | 22 | public function register_routes() { |
| 23 | 23 | $this->get( 'items', [ $this, 'get_items' ], [ |
| 24 | 24 | 'type' => [ |
| 25 | 25 | 'default' => 'items', |
| 26 | - 'required' => false | |
| 26 | + 'required' => false, | |
| 27 | + // 'validate_callback' => function( $param, $request, $key ){ | |
| 28 | + // return in_array( $param, [ 'items', 'sections', 'blocks', 'packs', 'pages' ], true ); | |
| 29 | + // } | |
| 27 | 30 | ], |
| 28 | 31 | 'platform' => [ |
| 29 | 32 | 'default' => 'elementor', |
| 30 | 33 | 'required' => false |
| @@ -66,9 +69,10 @@ | ||
| 66 | 69 | * |
| 67 | 70 | * @return string |
| 68 | 71 | */ |
| 69 | 72 | public function get_query_types( $type = 'blocks' ) { |
| 70 | - return ( $type === 'blocks' || $type === 'sections' ) ? 'items' : trim( $type ); | |
| 73 | + $item_types = ( $type === 'blocks' || $type === 'sections' ) ? 'items' : trim( $type ); | |
| 74 | + return in_array( $item_types, [ 'items', 'pages', 'packs' ], true ) ? $item_types : false; | |
| 71 | 75 | } |
| 72 | 76 | |
| 73 | 77 | public function get_items( WP_REST_Request $request ) { |
| 74 | 78 | $_type = $this->get_param( 'type', 'blocks' ); |
| @@ -116,8 +120,12 @@ | ||
| 116 | 120 | if( $type !== 'packs' ) { |
| 117 | 121 | $query = 'total_page, current_page, data { id, name, price, rating, downloads, type, template_type{ slug }, slug, favourite_count, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }, thumbnail }'; |
| 118 | 122 | } |
| 119 | 123 | |
| 124 | + if( $type === false ) { | |
| 125 | + return $this->error( 'invalid_type_call', __( 'Invalid Type Call', 'templately' ) ); | |
| 126 | + } | |
| 127 | + | |
| 120 | 128 | return $this->http()->query( |
| 121 | 129 | $type, |
| 122 | 130 | $query, |
| 123 | 131 | $funcArgs |
| @@ -135,8 +143,12 @@ | ||
| 135 | 143 | __( 'Items slug cannot be empty.', 'templately' ), |
| 136 | 144 | 'items/:slug', |
| 137 | 145 | '400' |
| 138 | 146 | ); |
| 147 | + } | |
| 148 | + | |
| 149 | + if( $type === false ) { | |
| 150 | + return $this->error( 'invalid_type_call', __( 'Invalid Type Call', 'templately' ) ); | |
| 139 | 151 | } |
| 140 | 152 | |
| 141 | 153 | $items_params = 'id, name, rating, type, description, slug, price, features, favourite_count, thumbnail, downloads, categories{ id, name, slug }, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }, tags{ name, id }, categories{ name, id }, screenshots{ url }, banner, pack{ id, name, slug, items{ id, price, name, type, slug, thumbnail } }, live_url, template_type{ id, name, slug }'; |
| 142 | 154 | $params = 'data { ' . $items_params . ' }'; |