paginated-args.php
27 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Components\Rest_Api\Traits; |
| 5 | |
| 6 | use Jet_Form_Builder\Db_Queries\Views\View_Base; |
| 7 | |
| 8 | // If this file is called directly, abort. |
| 9 | if ( ! defined( 'WPINC' ) ) { |
| 10 | die; |
| 11 | } |
| 12 | |
| 13 | trait Paginated_Args { |
| 14 | |
| 15 | protected function get_paginate_args( \WP_REST_Request $request ) { |
| 16 | $body = $request->get_query_params(); |
| 17 | |
| 18 | return array( |
| 19 | 'limit' => (int) ( $body['limit'] ?? 5 ), |
| 20 | 'sort' => $body['sort'] ?? View_Base::FROM_HIGH_TO_LOW, |
| 21 | 'page' => (int) ( $body['page'] ?? 1 ), |
| 22 | 'filters' => (array) ( $body['filters'] ?? array() ), |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | } |
| 27 |