array( 'type' => 'integer', 'default' => 1, 'minimum' => 1 ), 'per_page' => array( 'type' => 'integer', 'default' => 25, 'minimum' => 1, 'maximum' => 200 ), 'orderby' => array( 'type' => 'string' ), 'order' => array( 'type' => 'string', 'enum' => array( 'ASC', 'DESC' ), 'default' => 'DESC' ), 'search' => array( 'type' => 'string' ), 'filter' => array( 'type' => 'string', 'description' => __( 'Coverage-state filter, e.g. indexed or excluded.', 'acrossai-abilities-manager' ) ), 'filter_type' => array( 'type' => 'string', 'description' => __( 'Which field the filter applies to.', 'acrossai-abilities-manager' ) ), ); } protected function output_properties(): array { return array( 'results' => array( 'type' => 'array' ), 'total' => array( 'type' => 'integer' ), ); } protected function required_input(): array { return array(); } protected function annotations(): array { return array( 'readonly' => true, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { $per_page = isset( $input['per_page'] ) ? max( 1, min( 200, (int) $input['per_page'] ) ) : 25; $result = Analytics_Repository::inspections( array( 'page' => isset( $input['page'] ) ? max( 1, (int) $input['page'] ) : 1, 'perPage' => $per_page, 'orderBy' => isset( $input['orderby'] ) ? sanitize_key( (string) $input['orderby'] ) : '', 'order' => isset( $input['order'] ) && 'ASC' === strtoupper( (string) $input['order'] ) ? 'ASC' : 'DESC', 'search' => isset( $input['search'] ) ? sanitize_text_field( (string) $input['search'] ) : '', 'filter' => isset( $input['filter'] ) ? sanitize_text_field( (string) $input['filter'] ) : '', 'filterType' => isset( $input['filter_type'] ) ? sanitize_key( (string) $input['filter_type'] ) : '', ), $per_page ); if ( is_wp_error( $result ) ) { return $result; } $result['message'] = sprintf( /* translators: 1: number of rows returned, 2: total rows available */ __( 'Returned %1$d of %2$d URL Inspection results.', 'acrossai-abilities-manager' ), count( $result['results'] ), $result['total'] ); return $result; } }