| 1 |
<?php |
| 2 |
namespace Barn2\Plugin\Posts_Table_Search_Sort; |
| 3 |
|
| 4 |
/** |
| 5 |
* Responsible for fetching and sanitizing the plugin settings. |
| 6 |
* |
| 7 |
* @package Barn2\posts-table-search-sort |
| 8 |
* @author Barn2 Plugins <support@barn2.com> |
| 9 |
* @license GPL-3.0 |
| 10 |
* @copyright Barn2 Media Ltd |
| 11 |
*/ |
| 12 |
class Settings { |
| 13 |
|
| 14 |
const TABLE_ARGS_SETTING = 'ptss_table_args'; |
| 15 |
|
| 16 |
public static function get_table_args() { |
| 17 |
return get_option( self::TABLE_ARGS_SETTING, [] ); |
| 18 |
} |
| 19 |
|
| 20 |
public static function sanitize_table_args( $args ) { |
| 21 |
if ( isset( $args['columns'] ) ) { |
| 22 |
$args['columns'] = sanitize_text_field( $args['columns'] ); |
| 23 |
} |
| 24 |
if ( isset( $args['content_length'] ) ) { |
| 25 |
$args['content_length'] = filter_var( |
| 26 |
$args['content_length'], |
| 27 |
FILTER_VALIDATE_INT, |
| 28 |
[ |
| 29 |
'options' => [ |
| 30 |
'min' => -1 |
| 31 |
] |
| 32 |
] |
| 33 |
); |
| 34 |
} |
| 35 |
if ( isset( $args['rows_per_page'] ) ) { |
| 36 |
$args['rows_per_page'] = filter_var( |
| 37 |
$args['rows_per_page'], |
| 38 |
FILTER_VALIDATE_INT, |
| 39 |
[ |
| 40 |
'options' => [ |
| 41 |
'min' => -1 |
| 42 |
] |
| 43 |
] |
| 44 |
); |
| 45 |
} |
| 46 |
if ( isset( $args['sort_by'] ) ) { |
| 47 |
$args['sort_by'] = sanitize_key( $args['sort_by'] ); |
| 48 |
} |
| 49 |
if ( isset( $args['sort_order'] ) && ! in_array( $args['sort_order'], [ 'asc', 'desc', '' ] ) ) { |
| 50 |
$args['sort_order'] = ''; |
| 51 |
} |
| 52 |
|
| 53 |
return $args; |
| 54 |
} |
| 55 |
|
| 56 |
} |
| 57 |
|