| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JFB_Modules\Option_Query\Traits; |
| 5 |
|
| 6 |
// If this file is called directly, abort. |
| 7 |
if ( ! defined( 'WPINC' ) ) { |
| 8 |
die; |
| 9 |
} |
| 10 |
|
| 11 |
trait Option_Query_Trait { |
| 12 |
|
| 13 |
/** |
| 14 |
* Settings which used to display fetched things |
| 15 |
* |
| 16 |
* @var array |
| 17 |
*/ |
| 18 |
protected $settings = array(); |
| 19 |
|
| 20 |
/** |
| 21 |
* Settings which used to query things |
| 22 |
* |
| 23 |
* @var array |
| 24 |
*/ |
| 25 |
protected $query = array(); |
| 26 |
|
| 27 |
protected $features = array( |
| 28 |
'search' => true, |
| 29 |
); |
| 30 |
|
| 31 |
public function set_setting( string $name, $value ) { |
| 32 |
$this->settings[ $name ] = $value; |
| 33 |
} |
| 34 |
|
| 35 |
public function get_setting( string $name ) { |
| 36 |
return $this->settings[ $name ] ?? false; |
| 37 |
} |
| 38 |
|
| 39 |
public function has_setting( string $name ): bool { |
| 40 |
return array_key_exists( $name, $this->settings ); |
| 41 |
} |
| 42 |
|
| 43 |
public function set_settings( array $settings ) { |
| 44 |
$this->settings = $settings; |
| 45 |
} |
| 46 |
|
| 47 |
public function get_settings(): array { |
| 48 |
return $this->settings; |
| 49 |
} |
| 50 |
|
| 51 |
public function set_query( string $name, $value ) { |
| 52 |
$this->query[ $name ] = $value; |
| 53 |
} |
| 54 |
|
| 55 |
public function get_query( string $name ) { |
| 56 |
return $this->query[ $name ] ?? false; |
| 57 |
} |
| 58 |
|
| 59 |
public function has_query( string $name ): bool { |
| 60 |
return array_key_exists( $name, $this->query ); |
| 61 |
} |
| 62 |
|
| 63 |
public function delete_query( string $name ) { |
| 64 |
unset( $this->query[ $name ] ); |
| 65 |
} |
| 66 |
|
| 67 |
public function set_query_params( array $params ) { |
| 68 |
$this->query = $params; |
| 69 |
} |
| 70 |
|
| 71 |
public function get_query_params(): array { |
| 72 |
return $this->query; |
| 73 |
} |
| 74 |
|
| 75 |
public function is_support_feature( string $feature_name ): bool { |
| 76 |
return (bool) ( $this->features[ $feature_name ] ?? false ); |
| 77 |
} |
| 78 |
|
| 79 |
public function disable_feature( string $feature_name ) { |
| 80 |
unset( $this->features[ $feature_name ] ); |
| 81 |
} |
| 82 |
|
| 83 |
public function enable_feature( string $feature_name ) { |
| 84 |
$this->features[ $feature_name ] = true; |
| 85 |
} |
| 86 |
|
| 87 |
} |
| 88 |
|