|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* Handles the WordLift Plugin configuration by providing |
|
4
|
|
|
* * configuration screens |
|
5
|
|
|
* * methods for retrieving configuration data |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
require_once( 'wordlift_configuration_constants.php' ); |
|
9
|
|
|
require_once( 'wordlift_configuration_settings.php' ); |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* This function is called by the *wl_admin_menu* hook which is raised when WordLift builds the admin_menu. |
|
13
|
|
|
* |
|
14
|
|
|
* @since 3.0.0 |
|
15
|
|
|
* |
|
16
|
|
|
* @param string $parent_slug The parent slug for the menu. |
|
17
|
|
|
* @param string $capability The required capability to access the page. |
|
18
|
|
|
*/ |
|
19
|
|
|
function wl_configuration_admin_menu( $parent_slug, $capability ) { |
|
20
|
|
|
|
|
21
|
|
|
// see http://codex.wordpress.org/Function_Reference/add_submenu_page |
|
22
|
|
|
add_submenu_page( |
|
23
|
|
|
$parent_slug, // The parent menu slug, provided by the calling hook. |
|
24
|
|
|
__( 'Settings', 'wordlift' ), // page title |
|
25
|
|
|
__( 'Settings', 'wordlift' ), // menu title |
|
26
|
|
|
$capability, // The required capability, provided by the calling hook. |
|
27
|
|
|
'wl_configuration_admin_menu', // the menu slug |
|
28
|
|
|
'wl_configuration_admin_menu_callback' // the menu callback for displaying the page content |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
add_action( 'wl_admin_menu', 'wl_configuration_admin_menu', 10, 2 ); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Displays the page content. |
|
37
|
|
|
* |
|
38
|
|
|
* @since 3.0.0 |
|
39
|
|
|
* |
|
40
|
|
|
* @param boolean $display_page_title If true, prints out the page title. |
|
41
|
|
|
*/ |
|
42
|
|
|
function wl_configuration_admin_menu_callback( $display_page_title = true ) { |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
if ( ! current_user_can( 'manage_options' ) ) { |
|
45
|
|
|
wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
// Ony show advanced settings tab if the relative constant exists and is set to true. |
|
49
|
|
|
$can_show_advanced_settings = defined( 'WL_ENABLE_ADVANCED_CONFIGURATION' ) && WL_ENABLE_ADVANCED_CONFIGURATION; |
|
50
|
|
|
|
|
51
|
|
|
?> |
|
52
|
|
|
|
|
53
|
|
|
<div class="wrap" > |
|
54
|
|
|
|
|
55
|
|
|
<?php if ( $display_page_title ) { ?> |
|
56
|
|
|
<div id="icon-themes" class="icon32" ></div > |
|
57
|
|
|
<h2 >WordLift</h2 > |
|
58
|
|
|
<?php } ?> |
|
59
|
|
|
|
|
60
|
|
|
<?php settings_errors(); ?> |
|
61
|
|
|
|
|
62
|
|
|
<?php |
|
63
|
|
|
$active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general_settings'; |
|
64
|
|
|
?> |
|
65
|
|
|
|
|
66
|
|
|
<h2 class="nav-tab-wrapper" > |
|
67
|
|
|
<a href="?page=<?php echo( $_GET['page'] ); ?>&tab=general_settings" |
|
68
|
|
|
class="nav-tab <?php echo $active_tab == 'general_settings' ? 'nav-tab-active' : ''; ?>" ><?php esc_attr_e( 'General', 'wordlift' ); ?></a > |
|
69
|
|
|
|
|
70
|
|
|
<?php if ( $can_show_advanced_settings ): ?> |
|
71
|
|
|
<a href="?page=<?php echo( $_GET['page'] ); ?>&tab=advanced_settings" |
|
72
|
|
|
class="nav-tab <?php echo $active_tab == 'advanced_settings' ? 'nav-tab-active' : ''; ?>" ><?php esc_attr_e( 'Advanced', 'wordlift' ); ?></a > |
|
73
|
|
|
<?php endif; ?> |
|
74
|
|
|
</h2 > |
|
75
|
|
|
|
|
76
|
|
|
<form action="options.php" method="post" > |
|
77
|
|
|
<?php |
|
78
|
|
|
if ( 'general_settings' === $active_tab ) { |
|
79
|
|
|
settings_fields( 'wl_general_settings' ); |
|
80
|
|
|
do_settings_sections( 'wl_general_settings' ); |
|
81
|
|
|
|
|
82
|
|
|
} else if ( $can_show_advanced_settings && 'advanced_settings' === $active_tab ) { |
|
83
|
|
|
settings_fields( 'wl_advanced_settings' ); |
|
84
|
|
|
do_settings_sections( 'wl_advanced_settings' ); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
submit_button(); |
|
88
|
|
|
?> |
|
89
|
|
|
</form > |
|
90
|
|
|
|
|
91
|
|
|
<div style="margin-top: 100px; font-size: 10px;" >The entities blocks |
|
92
|
|
|
are |
|
93
|
|
|
designed by Lukasz M. Pogoda from the |
|
94
|
|
|
Noun Project |
|
95
|
|
|
</div > |
|
96
|
|
|
</div > |
|
97
|
|
|
|
|
98
|
|
|
<?php |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Configure all the configuration parameters. The configuration parameters are grouped in two tabs: |
|
104
|
|
|
* * General |
|
105
|
|
|
* * Advanced (only available if the WL_ENABLE_ADVANCED_CONFIGURATION constant exists and is set to True) |
|
106
|
|
|
* |
|
107
|
|
|
* Called by the *admin_init* hook. |
|
108
|
|
|
* |
|
109
|
|
|
* @since 3.0.0 |
|
110
|
|
|
*/ |
|
111
|
|
|
function wl_configuration_settings() { |
|
112
|
|
|
|
|
113
|
|
|
register_setting( |
|
114
|
|
|
'wl_general_settings', |
|
115
|
|
|
'wl_general_settings', |
|
116
|
|
|
'wl_configuration_sanitize_settings' |
|
117
|
|
|
); |
|
118
|
|
|
|
|
119
|
|
|
add_settings_section( |
|
120
|
|
|
'wl_general_settings_section', // ID used to identify this section and with which to register options |
|
121
|
|
|
'General Settings', // Title to be displayed on the administration page |
|
122
|
|
|
'wl_configuration_general_settings_section_callback', // Callback used to render the description of the section |
|
123
|
|
|
'wl_general_settings' // Page on which to add this section of options |
|
124
|
|
|
); |
|
125
|
|
|
|
|
126
|
|
|
add_settings_field( |
|
127
|
|
|
WL_CONFIG_WORDLIFT_KEY, // ID used to identify the field throughout the theme |
|
128
|
|
|
__( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element |
|
129
|
|
|
'wl_configuration_input_box', // The name of the function responsible for rendering the option interface |
|
130
|
|
|
'wl_general_settings', // The page on which this option will be displayed |
|
131
|
|
|
'wl_general_settings_section', // The name of the section to which this field belongs |
|
132
|
|
|
array( // The array of arguments to pass to the callback. In this case, just a description. |
|
133
|
|
|
'id' => 'wl-key', |
|
134
|
|
|
'name' => 'wl_general_settings[key]', |
|
135
|
|
|
'value' => wl_configuration_get_key(), |
|
|
|
|
|
|
136
|
|
|
'description' => __( 'Insert the WordLift Key', 'wordlift' ), |
|
137
|
|
|
) |
|
138
|
|
|
); |
|
139
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
// Entity Base Path input. |
|
142
|
|
|
|
|
143
|
|
|
$entity_base_path_args = array( // The array of arguments to pass to the callback. In this case, just a description. |
|
144
|
|
|
'id' => 'wl-entity-base-path', |
|
145
|
|
|
'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
146
|
|
|
'value' => Wordlift_Configuration_Service::get_instance() |
|
147
|
|
|
->get_entity_base_path(), |
|
148
|
|
|
'description' => __( 'Insert the Entity Base Path', 'wordlift' ), |
|
149
|
|
|
); |
|
150
|
|
|
|
|
151
|
|
|
if ( Wordlift_Entity_Service::get_instance()->count() ) { |
|
152
|
|
|
// Mark the field readonly, the value can be anything. |
|
153
|
|
|
$entity_base_path_args['readonly'] = ''; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
add_settings_field( |
|
157
|
|
|
Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY, // ID used to identify the field throughout the theme |
|
158
|
|
|
__( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
159
|
|
|
'wl_configuration_input_box', // The name of the function responsible for rendering the option interface |
|
160
|
|
|
'wl_general_settings', // The page on which this option will be displayed |
|
161
|
|
|
'wl_general_settings_section', // The name of the section to which this field belongs |
|
162
|
|
|
$entity_base_path_args |
|
163
|
|
|
); |
|
164
|
|
|
|
|
165
|
|
|
// Site Language input. |
|
166
|
|
|
|
|
167
|
|
|
add_settings_field( |
|
168
|
|
|
WL_CONFIG_SITE_LANGUAGE_NAME, |
|
169
|
|
|
__( 'Site Language', 'wordlift' ), |
|
170
|
|
|
'wl_configuration_select', |
|
171
|
|
|
'wl_general_settings', |
|
172
|
|
|
'wl_general_settings_section', |
|
173
|
|
|
array( // The array of arguments to pass to the callback. In this case, just a description. |
|
174
|
|
|
'id' => 'wl-site-language', |
|
175
|
|
|
'name' => 'wl_general_settings[site_language]', |
|
176
|
|
|
'value' => wl_configuration_get_site_language(), |
|
|
|
|
|
|
177
|
|
|
'description' => __( 'The site language', 'wordlift' ), |
|
178
|
|
|
'options' => wl_configuration_get_languages(), |
|
179
|
|
|
) |
|
180
|
|
|
); |
|
181
|
|
|
|
|
182
|
|
|
if ( defined( 'WL_ENABLE_ADVANCED_CONFIGURATION' ) && WL_ENABLE_ADVANCED_CONFIGURATION ) { |
|
183
|
|
|
|
|
184
|
|
|
register_setting( |
|
185
|
|
|
'wl_advanced_settings', |
|
186
|
|
|
'wl_advanced_settings', |
|
187
|
|
|
'wl_configuration_sanitize_settings' |
|
188
|
|
|
); |
|
189
|
|
|
|
|
190
|
|
|
add_settings_section( |
|
191
|
|
|
'wl_advanced_settings_section', // ID used to identify this section and with which to register options |
|
192
|
|
|
'Advanced', // Title to be displayed on the administration page |
|
193
|
|
|
'wl_configuration_advanced_settings_section_callback', // Callback used to render the description of the section |
|
194
|
|
|
'wl_advanced_settings' // Page on which to add this section of options |
|
195
|
|
|
); |
|
196
|
|
|
|
|
197
|
|
|
add_settings_field( |
|
198
|
|
|
WL_CONFIG_API_URL, // ID used to identify the field throughout the theme |
|
199
|
|
|
__( 'API URL', 'wordlift' ), // The label to the left of the option interface element |
|
200
|
|
|
'wl_configuration_input_box', // The name of the function responsible for rendering the option interface |
|
201
|
|
|
'wl_advanced_settings', // The page on which this option will be displayed |
|
202
|
|
|
'wl_advanced_settings_section', // The name of the section to which this field belongs |
|
203
|
|
|
array( // The array of arguments to pass to the callback. In this case, just a description. |
|
204
|
|
|
'id' => 'wl-api-url', |
|
205
|
|
|
'name' => 'wl_advanced_settings[api_url]', |
|
206
|
|
|
'value' => wl_configuration_get_api_url(), |
|
207
|
|
|
'description' => __( 'The API URL', 'wordlift' ), |
|
208
|
|
|
) |
|
209
|
|
|
); |
|
210
|
|
|
|
|
211
|
|
|
add_settings_field( |
|
212
|
|
|
WL_CONFIG_APPLICATION_KEY_NAME, // ID used to identify the field throughout the theme |
|
213
|
|
|
__( 'Redlink Key', 'wordlift' ), // The label to the left of the option interface element |
|
214
|
|
|
'wl_configuration_input_box', // The name of the function responsible for rendering the option interface |
|
215
|
|
|
'wl_advanced_settings', // The page on which this option will be displayed |
|
216
|
|
|
'wl_advanced_settings_section', // The name of the section to which this field belongs |
|
217
|
|
|
array( // The array of arguments to pass to the callback. In this case, just a description. |
|
218
|
|
|
'id' => 'wl-redlink-key', |
|
219
|
|
|
'name' => 'wl_advanced_settings[redlink_key]', |
|
220
|
|
|
'value' => wl_configuration_get_redlink_key(), |
|
221
|
|
|
'description' => __( 'The Redlink key', 'wordlift' ), |
|
222
|
|
|
) |
|
223
|
|
|
); |
|
224
|
|
|
|
|
225
|
|
|
add_settings_field( |
|
226
|
|
|
WL_CONFIG_USER_ID_NAME, // ID used to identify the field throughout the theme |
|
227
|
|
|
__( 'Redlink User Id', 'wordlift' ), // The label to the left of the option interface element |
|
228
|
|
|
'wl_configuration_input_box', // The name of the function responsible for rendering the option interface |
|
229
|
|
|
'wl_advanced_settings', // The page on which this option will be displayed |
|
230
|
|
|
'wl_advanced_settings_section', // The name of the section to which this field belongs |
|
231
|
|
|
array( // The array of arguments to pass to the callback. In this case, just a description. |
|
232
|
|
|
'id' => 'wl-redlink-user-id', |
|
233
|
|
|
'name' => 'wl_advanced_settings[redlink_user_id]', |
|
234
|
|
|
'value' => wl_configuration_get_redlink_user_id(), |
|
235
|
|
|
'description' => __( 'The Redlink User Id', 'wordlift' ), |
|
236
|
|
|
) |
|
237
|
|
|
); |
|
238
|
|
|
|
|
239
|
|
|
add_settings_field( |
|
240
|
|
|
WL_CONFIG_DATASET_NAME, // ID used to identify the field throughout the theme |
|
241
|
|
|
__( 'Redlink Dataset name', 'wordlift' ), // The label to the left of the option interface element |
|
242
|
|
|
'wl_configuration_input_box', // The name of the function responsible for rendering the option interface |
|
243
|
|
|
'wl_advanced_settings', // The page on which this option will be displayed |
|
244
|
|
|
'wl_advanced_settings_section', // The name of the section to which this field belongs |
|
245
|
|
|
array( // The array of arguments to pass to the callback. In this case, just a description. |
|
246
|
|
|
'id' => 'wl-redlink-dataset-name', |
|
247
|
|
|
'name' => 'wl_advanced_settings[redlink_dataset_name]', |
|
248
|
|
|
'value' => wl_configuration_get_redlink_dataset_name(), |
|
249
|
|
|
'description' => __( 'The Redlink Dataset Name', 'wordlift' ), |
|
250
|
|
|
) |
|
251
|
|
|
); |
|
252
|
|
|
|
|
253
|
|
|
add_settings_field( |
|
254
|
|
|
WL_CONFIG_DATASET_BASE_URI_NAME, // ID used to identify the field throughout the theme |
|
255
|
|
|
__( 'Redlink Dataset URI', 'wordlift' ), // The label to the left of the option interface element |
|
256
|
|
|
'wl_configuration_input_box', // The name of the function responsible for rendering the option interface |
|
257
|
|
|
'wl_advanced_settings', // The page on which this option will be displayed |
|
258
|
|
|
'wl_advanced_settings_section', // The name of the section to which this field belongs |
|
259
|
|
|
array( // The array of arguments to pass to the callback. In this case, just a description. |
|
260
|
|
|
'id' => 'wl-redlink-dataset-uri', |
|
261
|
|
|
'name' => 'wl_advanced_settings[redlink_dataset_uri]', |
|
262
|
|
|
'value' => wl_configuration_get_redlink_dataset_uri(), |
|
|
|
|
|
|
263
|
|
|
'description' => __( 'The Redlink Dataset URI', 'wordlift' ), |
|
264
|
|
|
) |
|
265
|
|
|
); |
|
266
|
|
|
|
|
267
|
|
|
add_settings_field( |
|
268
|
|
|
WL_CONFIG_ANALYSIS_NAME, // ID used to identify the field throughout the theme |
|
269
|
|
|
__( 'Redlink Application Name', 'wordlift' ), // The label to the left of the option interface element |
|
270
|
|
|
'wl_configuration_input_box', // The name of the function responsible for rendering the option interface |
|
271
|
|
|
'wl_advanced_settings', // The page on which this option will be displayed |
|
272
|
|
|
'wl_advanced_settings_section', // The name of the section to which this field belongs |
|
273
|
|
|
array( // The array of arguments to pass to the callback. In this case, just a description. |
|
274
|
|
|
'id' => 'wl-redlink-application-name', |
|
275
|
|
|
'name' => 'wl_advanced_settings[redlink_application_name]', |
|
276
|
|
|
'value' => wl_configuration_get_redlink_application_name(), |
|
277
|
|
|
'description' => __( 'The Redlink Application Name', 'wordlift' ), |
|
278
|
|
|
) |
|
279
|
|
|
); |
|
280
|
|
|
} |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
add_action( 'admin_init', 'wl_configuration_settings' ); |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* Display the general settings description. Called from a hook set by *wl_configuration_settings*. |
|
287
|
|
|
* |
|
288
|
|
|
* @since 3.0.0 |
|
289
|
|
|
*/ |
|
290
|
|
|
function wl_configuration_general_settings_section_callback() { |
|
291
|
|
|
|
|
292
|
|
|
// TODO: set the following text. |
|
293
|
|
|
?> |
|
294
|
|
|
Configure WordLift general options. |
|
295
|
|
|
<?php |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Display the advanced settings description. Called from a hook set by *wl_configuration_settings*. |
|
300
|
|
|
* |
|
301
|
|
|
* @since 3.0.0 |
|
302
|
|
|
*/ |
|
303
|
|
|
function wl_configuration_advanced_settings_section_callback() { |
|
304
|
|
|
|
|
305
|
|
|
// TODO: set the following text. |
|
306
|
|
|
?> |
|
307
|
|
|
Configure WordLift advanced options. |
|
308
|
|
|
<?php |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
/** |
|
312
|
|
|
* Sanitize the configuration settings to be stored. Configured as a hook from *wl_configuration_settings*. |
|
313
|
|
|
* |
|
314
|
|
|
* @since 3.0.0 |
|
315
|
|
|
* |
|
316
|
|
|
* @param array $input The configuration settings array. |
|
317
|
|
|
* |
|
318
|
|
|
* @return mixed |
|
319
|
|
|
*/ |
|
320
|
|
|
function wl_configuration_sanitize_settings( $input ) { |
|
321
|
|
|
|
|
322
|
|
|
// TODO: add sanitization checks. |
|
323
|
|
|
return apply_filters( 'wl_configuration_sanitize_settings', $input, $input ); |
|
324
|
|
|
|
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* Draw an input text with the provided parameters. |
|
329
|
|
|
* |
|
330
|
|
|
* @since 3.0.0 |
|
331
|
|
|
* |
|
332
|
|
|
* @param array $args An array of configuration parameters. |
|
333
|
|
|
*/ |
|
334
|
|
|
function wl_configuration_input_box( $args ) { |
|
335
|
|
|
?> |
|
336
|
|
|
<input type="text" id="<?php echo esc_attr( $args['id'] ); ?>" |
|
337
|
|
|
name="<?php echo esc_attr( $args['name'] ); ?>" |
|
338
|
|
|
value="<?php echo esc_attr( $args['value'] ); ?>" |
|
339
|
|
|
<?php if ( isset( $args['readonly'] ) ) { ?>readonly<?php } ?> |
|
340
|
|
|
/> |
|
341
|
|
|
|
|
342
|
|
|
<?php |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
/** |
|
346
|
|
|
* Display a select. |
|
347
|
|
|
* |
|
348
|
|
|
* @deprecated only used by the languages select. |
|
349
|
|
|
* |
|
350
|
|
|
* @see https://github.com/insideout10/wordlift-plugin/issues/349 |
|
351
|
|
|
* |
|
352
|
|
|
* @since 3.0.0 |
|
353
|
|
|
* |
|
354
|
|
|
* @param array $args The select configuration parameters. |
|
355
|
|
|
*/ |
|
356
|
|
|
function wl_configuration_select( $args ) { |
|
357
|
|
|
?> |
|
358
|
|
|
|
|
359
|
|
|
<select id="<?php echo esc_attr( $args['id'] ); ?>" |
|
360
|
|
|
name="<?php echo esc_attr( $args['name'] ); ?>" > |
|
361
|
|
|
<?php |
|
362
|
|
|
// Print all the supported language, preselecting the one configured in WP (or English if not supported). |
|
363
|
|
|
// We now use the `Wordlift_Languages` class which provides the list of languages supported by WordLift. |
|
364
|
|
|
// See https://github.com/insideout10/wordlift-plugin/issues/349 |
|
365
|
|
|
|
|
366
|
|
|
// Get WordLift's supported languages. |
|
367
|
|
|
$languages = Wordlift_Languages::get_languages(); |
|
368
|
|
|
|
|
369
|
|
|
// If we support WP's configured language, then use that, otherwise use English by default. |
|
370
|
|
|
$language = isset( $languages[ $args['value'] ] ) ? $args['value'] : 'en'; |
|
371
|
|
|
|
|
372
|
|
View Code Duplication |
foreach ( $languages as $code => $label ) { ?> |
|
|
|
|
|
|
373
|
|
|
<option |
|
374
|
|
|
value="<?php esc_attr_e( $code ) ?>" <?php echo selected( $code, $language, false ) ?>><?php esc_html_e( $label ) ?></option > |
|
375
|
|
|
<?php } ?> |
|
376
|
|
|
</select > |
|
377
|
|
|
|
|
378
|
|
|
<?php |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
/** |
|
382
|
|
|
* Display a checkbox. |
|
383
|
|
|
* |
|
384
|
|
|
* @since 3.0.0 |
|
385
|
|
|
* |
|
386
|
|
|
* @param array $args The checkbox parameters. |
|
387
|
|
|
*/ |
|
388
|
|
|
function wl_configuration_checkbox( $args ) { |
|
389
|
|
|
?> |
|
390
|
|
|
|
|
391
|
|
|
<input type="checkbox" id="<?php echo esc_attr( $args['id'] ); ?>" |
|
392
|
|
|
name="<?php echo esc_attr( $args['name'] ); ?>" |
|
393
|
|
|
value="1" <?php checked( 1, $args['value'], true ); ?>/> |
|
394
|
|
|
|
|
395
|
|
|
<?php |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
/** |
|
399
|
|
|
* Create a link to WordLift settings page. |
|
400
|
|
|
* |
|
401
|
|
|
* @since 3.0.0 |
|
402
|
|
|
* |
|
403
|
|
|
* @param array $links An array of links. |
|
404
|
|
|
* |
|
405
|
|
|
* @return array An array of links including those added by the plugin. |
|
406
|
|
|
*/ |
|
407
|
|
|
function wl_configuration_settings_links( $links ) { |
|
408
|
|
|
|
|
409
|
|
|
// TODO: this link is different within SEO Ultimate. |
|
410
|
|
|
array_push( $links, '<a href="' . get_admin_url( null, 'admin.php?page=wl_configuration_admin_menu' ) . '">Settings</a>' ); |
|
411
|
|
|
|
|
412
|
|
|
return $links; |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
// add the settings link for the plugin. |
|
416
|
|
|
add_filter( "plugin_action_links_wordlift/wordlift.php", 'wl_configuration_settings_links' ); |
|
417
|
|
|
|
|
418
|
|
|
|
|
419
|
|
|
/** |
|
420
|
|
|
* Get the available languages. |
|
421
|
|
|
* |
|
422
|
|
|
* @since 3.0.0 |
|
423
|
|
|
* |
|
424
|
|
|
* @return array An array of languages key values (key being the language code and values the language names). |
|
425
|
|
|
*/ |
|
426
|
|
|
function wl_configuration_get_languages() { |
|
427
|
|
|
|
|
428
|
|
|
// prepare the language array. |
|
429
|
|
|
$langs = array(); |
|
430
|
|
|
|
|
431
|
|
|
// set the path to the language file. |
|
432
|
|
|
$filename = dirname( __FILE__ ) . '/ISO-639-2_utf-8.txt'; |
|
433
|
|
|
|
|
434
|
|
|
if ( ( $handle = fopen( $filename, 'r' ) ) !== false ) { |
|
435
|
|
|
while ( ( $data = fgetcsv( $handle, 1000, '|' ) ) !== false ) { |
|
436
|
|
|
if ( ! empty( $data[2] ) ) { |
|
437
|
|
|
$code = $data[2]; |
|
438
|
|
|
$label = htmlentities( $data[3] ); |
|
439
|
|
|
$langs[ $code ] = $label; |
|
440
|
|
|
} |
|
441
|
|
|
} |
|
442
|
|
|
fclose( $handle ); |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
// sort the languages; |
|
446
|
|
|
asort( $langs ); |
|
447
|
|
|
|
|
448
|
|
|
return $langs; |
|
449
|
|
|
|
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
|
|
453
|
|
|
/** |
|
454
|
|
|
* Get the default recursion depth limitation on *entity metadata rendering*. |
|
455
|
|
|
* |
|
456
|
|
|
* @deprecated |
|
457
|
|
|
* @return string The default setting. |
|
458
|
|
|
*/ |
|
459
|
|
|
function wl_config_get_recursion_depth() { |
|
460
|
|
|
|
|
461
|
|
|
// get the plugin options. |
|
462
|
|
|
$options = get_option( WL_OPTIONS_NAME ); |
|
463
|
|
|
|
|
464
|
|
|
return ( isset( $options[ WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ] ) |
|
465
|
|
|
&& is_numeric( $options[ WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ] ) |
|
466
|
|
|
? $options[ WL_CONFIG_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ] |
|
467
|
|
|
: WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING ); |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
/** |
|
471
|
|
|
* Intercept the change of the WordLift key in order to set the dataset URI. |
|
472
|
|
|
* |
|
473
|
|
|
* @since 3.0.0 |
|
474
|
|
|
* |
|
475
|
|
|
* @param array $old_value The old settings. |
|
476
|
|
|
* @param array $new_value The new settings. |
|
477
|
|
|
*/ |
|
478
|
|
|
function wl_configuration_update_key( $old_value, $new_value ) { |
|
479
|
|
|
|
|
480
|
|
|
// wl_write_log( "Going to request set redlink dataset uri if needed" ); |
|
|
|
|
|
|
481
|
|
|
|
|
482
|
|
|
// Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed. |
|
483
|
|
|
$old_key = isset( $old_value['key'] ) ? $old_value['key'] : ''; |
|
484
|
|
|
$new_key = isset( $new_value['key'] ) ? $new_value['key'] : ''; |
|
485
|
|
|
|
|
486
|
|
|
// wl_write_log( "[ old value :: $old_key ][ new value :: $new_key ]" ); |
|
|
|
|
|
|
487
|
|
|
|
|
488
|
|
|
// If the key hasn't changed, don't do anything. |
|
489
|
|
|
// WARN The 'update_option' hook is fired only if the new and old value are not equal |
|
490
|
|
|
if ( $old_key === $new_key ) { |
|
491
|
|
|
return; |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
// If the key is empty, empty the dataset URI. |
|
495
|
|
|
if ( '' === $new_key ) { |
|
496
|
|
|
wl_configuration_set_redlink_dataset_uri( '' ); |
|
|
|
|
|
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
// Request the dataset URI. |
|
500
|
|
|
$response = wp_remote_get( wl_configuration_get_accounts_by_key_dataset_uri( $new_key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) ); |
|
501
|
|
|
|
|
502
|
|
|
// If the response is valid, then set the value. |
|
503
|
|
|
if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) { |
|
504
|
|
|
|
|
505
|
|
|
// wl_write_log( "[ Retrieved dataset :: " . $response['body'] . " ]" ); |
|
|
|
|
|
|
506
|
|
|
wl_configuration_set_redlink_dataset_uri( $response['body'] ); |
|
|
|
|
|
|
507
|
|
|
|
|
508
|
|
|
} else { |
|
509
|
|
|
wl_write_log( "Error on dataset uri remote retrieving [ " . var_export( $response, true ) . " ]" ); |
|
|
|
|
|
|
510
|
|
|
} |
|
511
|
|
|
|
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
add_action( 'update_option_wl_general_settings', 'wl_configuration_update_key', 10, 2 ); |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.