-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarkupMinifierWP.SettingsPage.php
137 lines (121 loc) · 3.43 KB
/
MarkupMinifierWP.SettingsPage.php
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
<?php
/*
* SettingsPage
*/
class MarkupMinifierWP_SettingsPage {
public function __construct() {
add_action('admin_menu', array($this, 'addPage'));
add_action('admin_init', array( $this, 'initPage'));
}
public function addPage() {
add_options_page(
MARKUP_MINIFIER_WP_NAME,
MARKUP_MINIFIER_WP_NAME,
'manage_options',
'markup-minifier-wp',
array($this, 'createPage')
);
}
public function createPage() {
$this->options = get_option('markup_minifier_wp_options');
?>
<div class="wrap">
<h1><?php echo MARKUP_MINIFIER_WP_NAME; ?></h1>
<p>
<b><?php echo MARKUP_MINIFIER_WP_DESCRIPTION; ?></b><br>
Find information, report issues and make contributions on <a href="<?php echo MARKUP_MINIFIER_WP_URL; ?>" title="<?php echo MARKUP_MINIFIER_WP_NAME; ?>" target="_blank">GitHub</a>.
</p>
<form method="post" action="options.php">
<?php
settings_fields('markup_minifier_wp');
do_settings_sections( 'markup-minifier-wp' );
submit_button();
?>
</form>
</div>
<?php
}
public function initPage() {
register_setting(
'markup_minifier_wp',
'markup_minifier_wp_options'
);
add_settings_section(
'general-settings',
'General Settings',
array(
$this,
'printGeneralInfo'
),
'markup-minifier-wp'
);
add_settings_field(
'compress-css',
'Compress CSS',
array(
$this,
'printCheckbox'
),
'markup-minifier-wp',
'general-settings',
array(
$this,
'field' => 'compress-css',
'description' => 'Minify inline styles'
)
);
add_settings_field(
'compress-js',
'Compress JS',
array(
$this,
'printCheckbox'
),
'markup-minifier-wp',
'general-settings',
array(
$this,
'field' => 'compress-js',
'description' => 'Minify inline scripts'
)
);
add_settings_field(
'remove-comments',
'Remove comments',
array(
$this,
'printCheckbox'
),
'markup-minifier-wp',
'general-settings',
array(
$this,
'field' => 'remove-comments',
'description' => 'Remove HTML comments'
)
);
add_settings_field(
'info-comment',
'Info comment',
array(
$this,
'printCheckbox'
),
'markup-minifier-wp',
'general-settings',
array(
$this,
'field' => 'info-comment',
'description' => 'Add info comment about file size savings'
)
);
}
public function printGeneralInfo() {
// print 'All HTML markup is minified by default. These settings are optional:';
}
public function printCheckbox($args) {
$field = $args['field'];
$checked = isset($this->options[$field]) ? ' checked' : '';
echo '<input type="checkbox" id="' . $field . '" name="markup_minifier_wp_options[' . $field . ']"' . $checked . '><label for="' . $field . '">' . $args['description'] . '</label>';
}
}