-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsettings.php
More file actions
136 lines (125 loc) · 4.66 KB
/
settings.php
File metadata and controls
136 lines (125 loc) · 4.66 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
<?php
// Settings Page: Hola
// Retrieving values: get_option( 'your_field_id' )
class Hola_Settings_Page {
public function __construct() {
add_action( 'admin_menu', array( $this, 'wph_create_settings' ) );
add_action( 'admin_init', array( $this, 'wph_setup_sections' ) );
add_action( 'admin_init', array( $this, 'wph_setup_fields' ) );
}
public function wph_create_settings() {
$page_title = 'Hola theme settings';
$menu_title = 'Hola';
$capability = 'manage_options';
$slug = 'Hola';
$callback = array($this, 'wph_settings_content');
$icon = 'dashicons-lightbulb';
$position = 1;
add_menu_page($page_title, $menu_title, $capability, $slug, $callback, $icon, $position);
}
public function wph_settings_content() { ?>
<div class="wrap">
<h1>Hola</h1>
<?php settings_errors(); ?>
<form method="POST" action="options.php">
<?php
settings_fields( 'Hola' );
do_settings_sections( 'Hola' );
settings_fields( 'Woocommerce' );
do_settings_sections( 'Woocommerce' );
settings_fields( 'Elementor' );
do_settings_sections( 'Elementor' );
submit_button();
?>
</form>
</div> <?php
}
public function wph_setup_sections() {
add_settings_section( 'hola_section', 'Aprender a dudar es aprender a pensar', array(), 'Hola' );
add_settings_section( 'woo_section', 'Your brand is what people say about you when you\'re not in the room', array(), 'Woocommerce' );
add_settings_section( 'elementor_section', '"Excellent!" I cried. "Elementary", said he', array(), 'Elementor' );
}
public function wph_setup_fields() {
$fields = array(
array(
'section' => 'hola_section',
'label' => 'Webp polyfill loader',
'id' => 'webp',
'desc' => 'Detects support and polyfill on-demand',
'type' => 'checkbox',
),
array(
'section' => 'hola_section',
'label' => 'Disable hola header',
'id' => 'no_header',
'desc' => 'Disables the template-parts/header.php',
'type' => 'checkbox',
),
array(
'section' => 'woo_section',
'label' => 'Filter woo styles',
'id' => 'no_woo_style',
'desc' => 'Filters woocommerce styles',
'type' => 'checkbox',
),
array(
'section' => 'elementor_section',
'label' => 'Filter google fonts',
'id' => 'no_e_google_fonts',
'desc' => 'Filters google fonts from elementor',
'type' => 'checkbox',
),
array(
'section' => 'elementor_section',
'label' => 'Filter font awesome',
'id' => 'no_e_font_awesome',
'desc' => 'Filters font awesome from elementor',
'type' => 'checkbox',
),
array(
'section' => 'elementor_section',
'label' => 'Dequeue eicons',
'id' => 'no_e_eicons',
'desc' => 'Dequeues eicons from elementor',
'type' => 'checkbox',
)
);
foreach( $fields as $field ){
add_settings_field( $field['id'], $field['label'], array( $this, 'wph_field_callback' ), 'Hola', $field['section'], $field );
add_settings_field( $field['id'], $field['label'], array( $this, 'wph_field_callback' ), 'Woocommerce', $field['section'], $field );
add_settings_field( $field['id'], $field['label'], array( $this, 'wph_field_callback' ), 'Elementor', $field['section'], $field );
register_setting( 'Hola', $field['id'] );
register_setting( 'Woocommerce', $field['id'] );
register_setting( 'Elementor', $field['id'] );
}
}
public function wph_field_callback( $field ) {
$value = get_option( $field['id'] );
$placeholder = '';
if ( isset($field['placeholder']) ) {
$placeholder = $field['placeholder'];
}
switch ( $field['type'] ) {
case 'checkbox':
printf('<input %s id="%s" name="%s" type="checkbox" value="1">',
$value === '1' ? 'checked' : '',
$field['id'],
$field['id']
);
break;
default:
printf( '<input name="%1$s" id="%1$s" type="%2$s" placeholder="%3$s" value="%4$s" />',
$field['id'],
$field['type'],
$placeholder,
$value
);
}
if( isset($field['desc']) ) {
if( $desc = $field['desc'] ) {
printf( '<p class="description">%s </p>', $desc );
}
}
}
}
new Hola_Settings_Page();