class-options.php
3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
namespace um\core;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'um\core\Options' ) ) {
/**
* Class Options
* @package um\core
*/
class Options {
/**
* @var array
*/
var $options = array();
/**
* Options constructor.
*/
function __construct() {
$this->init_variables();
}
/**
* Set variables
*/
function init_variables() {
$this->options = get_option( 'um_options', array() );
}
/**
* Get UM option value
*
* @param $option_id
* @return mixed|string|void
*/
function get( $option_id ) {
if ( isset( $this->options[ $option_id ] ) ) {
/**
* UM hook
*
* @type filter
* @title um_get_option_filter__{$option_id}
* @description Change UM option on get by $option_id
* @input_vars
* [{"var":"$option","type":"array","desc":"Option Value"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_get_option_filter__{$option_id}', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_get_option_filter__{$option_id}', 'my_get_option_filter', 10, 1 );
* function my_get_option_filter( $option ) {
* // your code here
* return $option;
* }
* ?>
*/
return apply_filters( "um_get_option_filter__{$option_id}", $this->options[ $option_id ] );
}
switch ( $option_id ) {
case 'site_name':
return get_bloginfo( 'name' );
break;
case 'admin_email':
return get_bloginfo( 'admin_email' );
break;
default:
return '';
break;
}
}
/**
* Update UM option value
*
* @param $option_id
* @param $value
*/
function update( $option_id, $value ) {
$this->options[ $option_id ] = $value;
update_option( 'um_options', $this->options );
}
/**
* Delete UM option
*
* @param $option_id
*/
function remove( $option_id ) {
if ( ! empty( $this->options[ $option_id ] ) ) {
unset( $this->options[ $option_id ] );
}
update_option( 'um_options', $this->options );
}
/**
* Get UM option default value
*
* @use UM()->config()
*
* @param $option_id
* @return mixed
*/
function get_default( $option_id ) {
$settings_defaults = UM()->config()->settings_defaults;
if ( ! isset( $settings_defaults[ $option_id ] ) ) {
return false;
}
return $settings_defaults[ $option_id ];
}
/**
* Get predefined page option key
*
* @since 2.8.3
*
* @param string $slug
*
* @return string
*/
public function get_predefined_page_option_key( $slug ) {
return apply_filters( 'um_predefined_page_option_key', "core_{$slug}" );
}
/**
* Get core page ID
*
* @param string $key
*
* @return mixed|void
*/
function get_core_page_id( $key ) {
/**
* UM hook
*
* @type filter
* @title um_core_page_id_filter
* @description Change UM page slug
* @input_vars
* [{"var":"$slug","type":"array","desc":"UM page slug"}]
* @change_log
* ["Since: 2.0"]
* @usage
* <?php add_filter( 'um_core_page_id_filter', 'function_name', 10, 1 ); ?>
* @example
* <?php
* add_filter( 'um_core_page_id_filter', 'my_core_page_id', 10, 1 );
* function my_core_page_id( $slug ) {
* // your code here
* return $slug;
* }
* ?>
*/
return apply_filters( 'um_core_page_id_filter', 'core_' . $key );
}
}
}