PluginProbe
Lawwwing | Textos legales web y Banner de cookies / trunk
Lawwwing | Textos legales web y Banner de cookies vtrunk
1.5.3 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 All 59 releases
ibamu / options / options-init.php

options-init.php in Lawwwing | Textos legales web y Banner de cookies trunk, at options/options-init.php

110 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Register settings and fields for the "ibamu" options page.
4 */
5 function lawwwing_settings_init() {
6 // Register a new setting for the "ibamu" page.
7 register_setting(
8 'ibamu',
9 'ibamu_options',
10 array(
11 'sanitize_callback' => 'lawwwing_sanitize_options',
12 )
13 );
14
15 // Register a new section in the "ibamu" page.
16 add_settings_section(
17 'ibamu_section_developers',
18 '', // No title for the section.
19 '', // No callback for the section.
20 'ibamu'
21 );
22
23 // Register a new field in the "ibamu_section_developers" section.
24 add_settings_field(
25 'ibamu_widget_uuid',
26 __('Plugin ID:', 'ibamu-plugin-domain'),
27 'lw_render_plugin_id_input',
28 'ibamu',
29 'ibamu_section_developers',
30 [
31 'label_for' => 'ibamu_widget_uuid',
32 'class' => 'lawwwing-row',
33 'ibamu_custom_data' => 'custom',
34 ]
35 );
36
37 // Migrate options to network mode if enabled.
38 if (defined('LW_NETWORK_MODE') && LW_NETWORK_MODE === true) {
39 $lw_options = get_option('ibamu_options');
40 if ($lw_options !== false) {
41 add_site_option('ibamu_options', $lw_options);
42 }
43 }
44 }
45 add_action('admin_init', 'lawwwing_settings_init');
46
47 /**
48 * Sanitize plugin options before persistence.
49 *
50 * @param array $input Raw options.
51 * @return array
52 */
53 function lawwwing_sanitize_options($input) {
54 $sanitized = is_array($input) ? $input : array();
55
56 if (isset($sanitized['ibamu_widget_uuid'])) {
57 $sanitized['ibamu_widget_uuid'] = sanitize_text_field($sanitized['ibamu_widget_uuid']);
58 }
59
60 return $sanitized;
61 }
62
63 /**
64 * Render the input field for the "Plugin ID".
65 *
66 * @param array $args Arguments for the field.
67 */
68 function lw_render_plugin_id_input($args) {
69 ?>
70 <input
71 id="<?php echo esc_attr($args['label_for']); ?>"
72 data-custom="<?php echo esc_attr($args['ibamu_custom_data']); ?>"
73 name="ibamu_options[<?php echo esc_attr($args['label_for']); ?>]"
74 value="<?php echo esc_attr(get_lawwwing_option('ibamu_widget_uuid')); ?>"
75 placeholder="Plugin id"
76 class="regular-text"
77 type="text"
78 required>
79 </input>
80 <p class="description">
81 <?php esc_html_e('Introduce el Plugin ID que encontrarĂ¡s en tu panel de Lawwwing', 'ibamu-plugin-domain'); ?>
82 </p>
83 <?php
84 }
85
86 /**
87 * Hook into options page after save.
88 * Save options in the network if network mode is activated.
89 *
90 * @param mixed $old_value The old option value.
91 * @param mixed $new_value The new option value.
92 */
93 function lw_hook_after_options_saved($old_value, $new_value) {
94 if (defined('LW_NETWORK_MODE') && LW_NETWORK_MODE === true) {
95 if ($old_value !== $new_value) {
96 update_site_option('ibamu_options', $new_value);
97 } else {
98 add_site_option('ibamu_options', $new_value);
99 }
100 } else {
101 if ($old_value !== $new_value) {
102 update_option('ibamu_options', $new_value);
103 } else {
104 add_option('ibamu_options', $new_value);
105 }
106 }
107 }
108 add_action('update_option_ibamu_options', 'lw_hook_after_options_saved', 10, 2);
109 ?>
110