# posts-data-table/trunk/src/Settings.php

Posts Table with Search &amp; Sort, version trunk. 57 lines.

- Page: https://pluginprobe.com/plugins/posts-data-table/trunk/code/src/Settings.php
- Raw: https://pluginprobe.com/plugins/posts-data-table/trunk/raw/src/Settings.php
- Modified: 2021-10-08T18:15:12+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/posts-data-table/trunk/code/src/Settings.php#L10-L20`.

```php
<?php
namespace Barn2\Plugin\Posts_Table_Search_Sort;

/**
 * Responsible for fetching and sanitizing the plugin settings.
 *
 * @package   Barn2\posts-table-search-sort
 * @author    Barn2 Plugins <support@barn2.com>
 * @license   GPL-3.0
 * @copyright Barn2 Media Ltd
 */
class Settings {

	const TABLE_ARGS_SETTING = 'ptss_table_args';

	public static function get_table_args() {
		return get_option( self::TABLE_ARGS_SETTING, [] );
	}

	public static function sanitize_table_args( $args ) {
		if ( isset( $args['columns'] ) ) {
			$args['columns'] = sanitize_text_field( $args['columns'] );
		}
		if ( isset( $args['content_length'] ) ) {
			$args['content_length'] = filter_var(
				$args['content_length'],
				FILTER_VALIDATE_INT,
				[
					'options' => [
						'min' => -1
					]
				]
			);
		}
		if ( isset( $args['rows_per_page'] ) ) {
			$args['rows_per_page'] = filter_var(
				$args['rows_per_page'],
				FILTER_VALIDATE_INT,
				[
					'options' => [
						'min' => -1
					]
				]
			);
		}
		if ( isset( $args['sort_by'] ) ) {
			$args['sort_by'] = sanitize_key( $args['sort_by'] );
		}
		if ( isset( $args['sort_order'] ) && ! in_array( $args['sort_order'], [ 'asc', 'desc', '' ] ) ) {
			$args['sort_order'] = '';
		}

		return $args;
	}

}

```
