PluginProbe
Posts Table with Search & Sort / trunk
Posts Table with Search & Sort vtrunk
trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2 1.3 1.3.1 1.3.1-v2 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 All 39 releases
posts-data-table / src / Settings.php

Settings.php in Posts Table with Search & Sort trunk, at src/Settings.php

57 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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