Version Description
- Initial Release.
=
Download this release
Release Info
Developer | hiddenpearls |
Plugin | Insert Headers And Footers |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- asset/css/style.css +6 -0
- classes/class-settings-api.php +623 -0
- classes/class-setup.php +102 -0
- readme.txt +53 -0
- wp-headers-and-footers.php +177 -0
asset/css/style.css
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.wp-header-and-footer .group h2{
|
2 |
+
display: none;
|
3 |
+
}
|
4 |
+
.wp-header-and-footer textarea{
|
5 |
+
width: 35em;
|
6 |
+
}
|
classes/class-settings-api.php
ADDED
@@ -0,0 +1,623 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* WP Header and Footer Settings API wrapper class
|
5 |
+
*/
|
6 |
+
if ( !class_exists( 'WPHeaderAndFooter_Settings_API' ) ):
|
7 |
+
class WPHeaderAndFooter_Settings_API {
|
8 |
+
|
9 |
+
/**
|
10 |
+
* settings sections array
|
11 |
+
*
|
12 |
+
* @var array
|
13 |
+
*/
|
14 |
+
protected $settings_sections = array();
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Settings fields array
|
18 |
+
*
|
19 |
+
* @var array
|
20 |
+
*/
|
21 |
+
protected $settings_fields = array();
|
22 |
+
|
23 |
+
public function __construct() {
|
24 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Enqueue scripts and styles
|
29 |
+
*/
|
30 |
+
function admin_enqueue_scripts() {
|
31 |
+
wp_enqueue_style( 'wp-color-picker' );
|
32 |
+
|
33 |
+
wp_enqueue_media();
|
34 |
+
wp_enqueue_script( 'wp-color-picker' );
|
35 |
+
wp_enqueue_script( 'jquery' );
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Set settings sections
|
40 |
+
*
|
41 |
+
* @param array $sections setting sections array
|
42 |
+
*/
|
43 |
+
function set_sections( $sections ) {
|
44 |
+
$this->settings_sections = $sections;
|
45 |
+
|
46 |
+
return $this;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Add a single section
|
51 |
+
*
|
52 |
+
* @param array $section
|
53 |
+
*/
|
54 |
+
function add_section( $section ) {
|
55 |
+
$this->settings_sections[] = $section;
|
56 |
+
|
57 |
+
return $this;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Set settings fields
|
62 |
+
*
|
63 |
+
* @param array $fields settings fields array
|
64 |
+
*/
|
65 |
+
function set_fields( $fields ) {
|
66 |
+
$this->settings_fields = $fields;
|
67 |
+
|
68 |
+
return $this;
|
69 |
+
}
|
70 |
+
|
71 |
+
function add_field( $section, $field ) {
|
72 |
+
$defaults = array(
|
73 |
+
'name' => '',
|
74 |
+
'label' => '',
|
75 |
+
'desc' => '',
|
76 |
+
'type' => 'text'
|
77 |
+
);
|
78 |
+
|
79 |
+
$arg = wp_parse_args( $field, $defaults );
|
80 |
+
$this->settings_fields[$section][] = $arg;
|
81 |
+
|
82 |
+
return $this;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Initialize and registers the settings sections and fileds to WordPress
|
87 |
+
*
|
88 |
+
* Usually this should be called at `admin_init` hook.
|
89 |
+
*
|
90 |
+
* This function gets the initiated settings sections and fields. Then
|
91 |
+
* registers them to WordPress and ready for use.
|
92 |
+
*/
|
93 |
+
function admin_init() {
|
94 |
+
//register settings sections
|
95 |
+
foreach ( $this->settings_sections as $section ) {
|
96 |
+
if ( false == get_option( $section['id'] ) ) {
|
97 |
+
add_option( $section['id'] );
|
98 |
+
}
|
99 |
+
|
100 |
+
if ( isset($section['desc']) && !empty($section['desc']) ) {
|
101 |
+
$section['desc'] = '<div class="inside">' . $section['desc'] . '</div>';
|
102 |
+
$callback = create_function('', 'echo "' . str_replace( '"', '\"', $section['desc'] ) . '";');
|
103 |
+
} else if ( isset( $section['callback'] ) ) {
|
104 |
+
$callback = $section['callback'];
|
105 |
+
} else {
|
106 |
+
$callback = null;
|
107 |
+
}
|
108 |
+
|
109 |
+
add_settings_section( $section['id'], $section['title'], $callback, $section['id'] );
|
110 |
+
}
|
111 |
+
|
112 |
+
//register settings fields
|
113 |
+
foreach ( $this->settings_fields as $section => $field ) {
|
114 |
+
foreach ( $field as $option ) {
|
115 |
+
|
116 |
+
$name = $option['name'];
|
117 |
+
$type = isset( $option['type'] ) ? $option['type'] : 'text';
|
118 |
+
$label = isset( $option['label'] ) ? $option['label'] : '';
|
119 |
+
$callback = isset( $option['callback'] ) ? $option['callback'] : array( $this, 'callback_' . $type );
|
120 |
+
|
121 |
+
$args = array(
|
122 |
+
'id' => $name,
|
123 |
+
'class' => isset( $option['class'] ) ? $option['class'] : $name,
|
124 |
+
'label_for' => "{$section}[{$name}]",
|
125 |
+
'desc' => isset( $option['desc'] ) ? $option['desc'] : '',
|
126 |
+
'name' => $label,
|
127 |
+
'section' => $section,
|
128 |
+
'size' => isset( $option['size'] ) ? $option['size'] : null,
|
129 |
+
'options' => isset( $option['options'] ) ? $option['options'] : '',
|
130 |
+
'std' => isset( $option['default'] ) ? $option['default'] : '',
|
131 |
+
'sanitize_callback' => isset( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : '',
|
132 |
+
'type' => $type,
|
133 |
+
'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : '',
|
134 |
+
'min' => isset( $option['min'] ) ? $option['min'] : '',
|
135 |
+
'max' => isset( $option['max'] ) ? $option['max'] : '',
|
136 |
+
'step' => isset( $option['step'] ) ? $option['step'] : '',
|
137 |
+
);
|
138 |
+
|
139 |
+
add_settings_field( "{$section}[{$name}]", $label, $callback, $section, $section, $args );
|
140 |
+
}
|
141 |
+
}
|
142 |
+
|
143 |
+
// creates our settings in the options table
|
144 |
+
foreach ( $this->settings_sections as $section ) {
|
145 |
+
register_setting( $section['id'], $section['id'], array( $this, 'sanitize_options' ) );
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Get field description for display
|
151 |
+
*
|
152 |
+
* @param array $args settings field args
|
153 |
+
*/
|
154 |
+
public function get_field_description( $args ) {
|
155 |
+
if ( ! empty( $args['desc'] ) ) {
|
156 |
+
$desc = sprintf( '<p class="description">%s</p>', $args['desc'] );
|
157 |
+
} else {
|
158 |
+
$desc = '';
|
159 |
+
}
|
160 |
+
|
161 |
+
return $desc;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Displays a text field for a settings field
|
166 |
+
*
|
167 |
+
* @param array $args settings field args
|
168 |
+
*/
|
169 |
+
function callback_text( $args ) {
|
170 |
+
|
171 |
+
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
|
172 |
+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
|
173 |
+
$type = isset( $args['type'] ) ? $args['type'] : 'text';
|
174 |
+
$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
|
175 |
+
|
176 |
+
$html = sprintf( '<input type="%1$s" class="%2$s-text" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder );
|
177 |
+
$html .= $this->get_field_description( $args );
|
178 |
+
|
179 |
+
echo $html;
|
180 |
+
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Displays a url field for a settings field
|
184 |
+
*
|
185 |
+
* @param array $args settings field args
|
186 |
+
*/
|
187 |
+
function callback_url( $args ) {
|
188 |
+
$this->callback_text( $args );
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Displays a number field for a settings field
|
193 |
+
*
|
194 |
+
* @param array $args settings field args
|
195 |
+
*/
|
196 |
+
function callback_number( $args ) {
|
197 |
+
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
|
198 |
+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
|
199 |
+
$type = isset( $args['type'] ) ? $args['type'] : 'number';
|
200 |
+
$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="' . $args['placeholder'] . '"';
|
201 |
+
$min = empty( $args['min'] ) ? '' : ' min="' . $args['min'] . '"';
|
202 |
+
$max = empty( $args['max'] ) ? '' : ' max="' . $args['max'] . '"';
|
203 |
+
$step = empty( $args['max'] ) ? '' : ' step="' . $args['step'] . '"';
|
204 |
+
|
205 |
+
$html = sprintf( '<input type="%1$s" class="%2$s-number" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s%7$s%8$s%9$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder, $min, $max, $step );
|
206 |
+
$html .= $this->get_field_description( $args );
|
207 |
+
|
208 |
+
echo $html;
|
209 |
+
}
|
210 |
+
|
211 |
+
/**
|
212 |
+
* Displays a checkbox for a settings field
|
213 |
+
*
|
214 |
+
* @param array $args settings field args
|
215 |
+
*/
|
216 |
+
function callback_checkbox( $args ) {
|
217 |
+
|
218 |
+
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
|
219 |
+
|
220 |
+
$html = '<fieldset>';
|
221 |
+
$html .= sprintf( '<label for="wpuf-%1$s[%2$s]">', $args['section'], $args['id'] );
|
222 |
+
$html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="off" />', $args['section'], $args['id'] );
|
223 |
+
$html .= sprintf( '<input type="checkbox" class="checkbox" id="wpuf-%1$s[%2$s]" name="%1$s[%2$s]" value="on" %3$s />', $args['section'], $args['id'], checked( $value, 'on', false ) );
|
224 |
+
$html .= sprintf( '%1$s</label>', $args['desc'] );
|
225 |
+
$html .= '</fieldset>';
|
226 |
+
|
227 |
+
echo $html;
|
228 |
+
}
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Displays a multicheckbox a settings field
|
232 |
+
*
|
233 |
+
* @param array $args settings field args
|
234 |
+
*/
|
235 |
+
function callback_multicheck( $args ) {
|
236 |
+
|
237 |
+
$value = $this->get_option( $args['id'], $args['section'], $args['std'] );
|
238 |
+
$html = '<fieldset>';
|
239 |
+
$html .= sprintf( '<input type="hidden" name="%1$s[%2$s]" value="" />', $args['section'], $args['id'] );
|
240 |
+
foreach ( $args['options'] as $key => $label ) {
|
241 |
+
$checked = isset( $value[$key] ) ? $value[$key] : '0';
|
242 |
+
$html .= sprintf( '<label for="wpuf-%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
|
243 |
+
$html .= sprintf( '<input type="checkbox" class="checkbox" id="wpuf-%1$s[%2$s][%3$s]" name="%1$s[%2$s][%3$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, checked( $checked, $key, false ) );
|
244 |
+
$html .= sprintf( '%1$s</label><br>', $label );
|
245 |
+
}
|
246 |
+
|
247 |
+
$html .= $this->get_field_description( $args );
|
248 |
+
$html .= '</fieldset>';
|
249 |
+
|
250 |
+
echo $html;
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Displays a multicheckbox a settings field
|
255 |
+
*
|
256 |
+
* @param array $args settings field args
|
257 |
+
*/
|
258 |
+
function callback_radio( $args ) {
|
259 |
+
|
260 |
+
$value = $this->get_option( $args['id'], $args['section'], $args['std'] );
|
261 |
+
$html = '<fieldset>';
|
262 |
+
|
263 |
+
foreach ( $args['options'] as $key => $label ) {
|
264 |
+
$html .= sprintf( '<label for="wpuf-%1$s[%2$s][%3$s]">', $args['section'], $args['id'], $key );
|
265 |
+
$html .= sprintf( '<input type="radio" class="radio" id="wpuf-%1$s[%2$s][%3$s]" name="%1$s[%2$s]" value="%3$s" %4$s />', $args['section'], $args['id'], $key, checked( $value, $key, false ) );
|
266 |
+
$html .= sprintf( '%1$s</label><br>', $label );
|
267 |
+
}
|
268 |
+
|
269 |
+
$html .= $this->get_field_description( $args );
|
270 |
+
$html .= '</fieldset>';
|
271 |
+
|
272 |
+
echo $html;
|
273 |
+
}
|
274 |
+
|
275 |
+
/**
|
276 |
+
* Displays a selectbox for a settings field
|
277 |
+
*
|
278 |
+
* @param array $args settings field args
|
279 |
+
*/
|
280 |
+
function callback_select( $args ) {
|
281 |
+
|
282 |
+
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
|
283 |
+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
|
284 |
+
$html = sprintf( '<select class="%1$s" name="%2$s[%3$s]" id="%2$s[%3$s]">', $size, $args['section'], $args['id'] );
|
285 |
+
|
286 |
+
foreach ( $args['options'] as $key => $label ) {
|
287 |
+
$html .= sprintf( '<option value="%s"%s>%s</option>', $key, selected( $value, $key, false ), $label );
|
288 |
+
}
|
289 |
+
|
290 |
+
$html .= sprintf( '</select>' );
|
291 |
+
$html .= $this->get_field_description( $args );
|
292 |
+
|
293 |
+
echo $html;
|
294 |
+
}
|
295 |
+
|
296 |
+
/**
|
297 |
+
* Displays a textarea for a settings field
|
298 |
+
*
|
299 |
+
* @param array $args settings field args
|
300 |
+
*/
|
301 |
+
function callback_textarea( $args ) {
|
302 |
+
|
303 |
+
$value = esc_textarea( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
|
304 |
+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
|
305 |
+
$placeholder = empty( $args['placeholder'] ) ? '' : ' placeholder="'.$args['placeholder'].'"';
|
306 |
+
|
307 |
+
$html = sprintf( '<textarea rows="5" cols="100" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]"%4$s>%5$s</textarea>', $size, $args['section'], $args['id'], $placeholder, $value );
|
308 |
+
$html .= $this->get_field_description( $args );
|
309 |
+
|
310 |
+
echo $html;
|
311 |
+
}
|
312 |
+
|
313 |
+
/**
|
314 |
+
* Displays a textarea for a settings field
|
315 |
+
*
|
316 |
+
* @param array $args settings field args
|
317 |
+
* @return string
|
318 |
+
*/
|
319 |
+
function callback_html( $args ) {
|
320 |
+
echo $this->get_field_description( $args );
|
321 |
+
}
|
322 |
+
|
323 |
+
/**
|
324 |
+
* Displays a rich text textarea for a settings field
|
325 |
+
*
|
326 |
+
* @param array $args settings field args
|
327 |
+
*/
|
328 |
+
function callback_wysiwyg( $args ) {
|
329 |
+
|
330 |
+
$value = $this->get_option( $args['id'], $args['section'], $args['std'] );
|
331 |
+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : '500px';
|
332 |
+
|
333 |
+
echo '<div style="max-width: ' . $size . ';">';
|
334 |
+
|
335 |
+
$editor_settings = array(
|
336 |
+
'teeny' => true,
|
337 |
+
'textarea_name' => $args['section'] . '[' . $args['id'] . ']',
|
338 |
+
'textarea_rows' => 10
|
339 |
+
);
|
340 |
+
|
341 |
+
if ( isset( $args['options'] ) && is_array( $args['options'] ) ) {
|
342 |
+
$editor_settings = array_merge( $editor_settings, $args['options'] );
|
343 |
+
}
|
344 |
+
|
345 |
+
wp_editor( $value, $args['section'] . '-' . $args['id'], $editor_settings );
|
346 |
+
|
347 |
+
echo '</div>';
|
348 |
+
|
349 |
+
echo $this->get_field_description( $args );
|
350 |
+
}
|
351 |
+
|
352 |
+
/**
|
353 |
+
* Displays a file upload field for a settings field
|
354 |
+
*
|
355 |
+
* @param array $args settings field args
|
356 |
+
*/
|
357 |
+
function callback_file( $args ) {
|
358 |
+
|
359 |
+
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
|
360 |
+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
|
361 |
+
$id = $args['section'] . '[' . $args['id'] . ']';
|
362 |
+
$label = isset( $args['options']['button_label'] ) ? $args['options']['button_label'] : __( 'Choose File' );
|
363 |
+
|
364 |
+
$html = sprintf( '<input type="text" class="%1$s-text wpsa-url" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
|
365 |
+
$html .= '<input type="button" class="button wpsa-browse" value="' . $label . '" />';
|
366 |
+
$html .= $this->get_field_description( $args );
|
367 |
+
|
368 |
+
echo $html;
|
369 |
+
}
|
370 |
+
|
371 |
+
/**
|
372 |
+
* Displays a password field for a settings field
|
373 |
+
*
|
374 |
+
* @param array $args settings field args
|
375 |
+
*/
|
376 |
+
function callback_password( $args ) {
|
377 |
+
|
378 |
+
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
|
379 |
+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
|
380 |
+
|
381 |
+
$html = sprintf( '<input type="password" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
|
382 |
+
$html .= $this->get_field_description( $args );
|
383 |
+
|
384 |
+
echo $html;
|
385 |
+
}
|
386 |
+
|
387 |
+
/**
|
388 |
+
* Displays a color picker field for a settings field
|
389 |
+
*
|
390 |
+
* @param array $args settings field args
|
391 |
+
*/
|
392 |
+
function callback_color( $args ) {
|
393 |
+
|
394 |
+
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
|
395 |
+
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
|
396 |
+
|
397 |
+
$html = sprintf( '<input type="text" class="%1$s-text wp-color-picker-field" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s" data-default-color="%5$s" />', $size, $args['section'], $args['id'], $value, $args['std'] );
|
398 |
+
$html .= $this->get_field_description( $args );
|
399 |
+
|
400 |
+
echo $html;
|
401 |
+
}
|
402 |
+
|
403 |
+
/**
|
404 |
+
* Sanitize callback for Settings API
|
405 |
+
*
|
406 |
+
* @return mixed
|
407 |
+
*/
|
408 |
+
function sanitize_options( $options ) {
|
409 |
+
|
410 |
+
if ( !$options ) {
|
411 |
+
return $options;
|
412 |
+
}
|
413 |
+
|
414 |
+
foreach( $options as $option_slug => $option_value ) {
|
415 |
+
$sanitize_callback = $this->get_sanitize_callback( $option_slug );
|
416 |
+
|
417 |
+
// If callback is set, call it
|
418 |
+
if ( $sanitize_callback ) {
|
419 |
+
$options[ $option_slug ] = call_user_func( $sanitize_callback, $option_value );
|
420 |
+
continue;
|
421 |
+
}
|
422 |
+
}
|
423 |
+
|
424 |
+
return $options;
|
425 |
+
}
|
426 |
+
|
427 |
+
/**
|
428 |
+
* Get sanitization callback for given option slug
|
429 |
+
*
|
430 |
+
* @param string $slug option slug
|
431 |
+
*
|
432 |
+
* @return mixed string or bool false
|
433 |
+
*/
|
434 |
+
function get_sanitize_callback( $slug = '' ) {
|
435 |
+
if ( empty( $slug ) ) {
|
436 |
+
return false;
|
437 |
+
}
|
438 |
+
|
439 |
+
// Iterate over registered fields and see if we can find proper callback
|
440 |
+
foreach( $this->settings_fields as $section => $options ) {
|
441 |
+
foreach ( $options as $option ) {
|
442 |
+
if ( $option['name'] != $slug ) {
|
443 |
+
continue;
|
444 |
+
}
|
445 |
+
|
446 |
+
// Return the callback name
|
447 |
+
return isset( $option['sanitize_callback'] ) && is_callable( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : false;
|
448 |
+
}
|
449 |
+
}
|
450 |
+
|
451 |
+
return false;
|
452 |
+
}
|
453 |
+
|
454 |
+
/**
|
455 |
+
* Get the value of a settings field
|
456 |
+
*
|
457 |
+
* @param string $option settings field name
|
458 |
+
* @param string $section the section name this field belongs to
|
459 |
+
* @param string $default default text if it's not found
|
460 |
+
* @return string
|
461 |
+
*/
|
462 |
+
function get_option( $option, $section, $default = '' ) {
|
463 |
+
|
464 |
+
$options = get_option( $section );
|
465 |
+
|
466 |
+
if ( isset( $options[$option] ) ) {
|
467 |
+
return $options[$option];
|
468 |
+
}
|
469 |
+
|
470 |
+
return $default;
|
471 |
+
}
|
472 |
+
|
473 |
+
/**
|
474 |
+
* Show navigations as tab
|
475 |
+
*
|
476 |
+
* Shows all the settings section labels as tab
|
477 |
+
*/
|
478 |
+
function show_navigation() {
|
479 |
+
$html = '<h2 class="nav-tab-wrapper">';
|
480 |
+
|
481 |
+
$count = count( $this->settings_sections );
|
482 |
+
|
483 |
+
// don't show the navigation if only one section exists
|
484 |
+
if ( $count === 1 ) {
|
485 |
+
// return;
|
486 |
+
}
|
487 |
+
|
488 |
+
foreach ( $this->settings_sections as $tab ) {
|
489 |
+
$html .= sprintf( '<a href="#%1$s" class="nav-tab" id="%1$s-tab">%2$s</a>', $tab['id'], $tab['title'] );
|
490 |
+
}
|
491 |
+
|
492 |
+
$html .= '</h2>';
|
493 |
+
|
494 |
+
echo $html;
|
495 |
+
}
|
496 |
+
|
497 |
+
/**
|
498 |
+
* Show the section settings forms
|
499 |
+
*
|
500 |
+
* This function displays every sections in a different form
|
501 |
+
*/
|
502 |
+
function show_forms() {
|
503 |
+
?>
|
504 |
+
<div class="metabox-holder">
|
505 |
+
<?php foreach ( $this->settings_sections as $form ) { ?>
|
506 |
+
<div id="<?php echo $form['id']; ?>" class="group" style="display: none;">
|
507 |
+
<form method="post" action="options.php">
|
508 |
+
<?php
|
509 |
+
do_action( 'wsa_form_top_' . $form['id'], $form );
|
510 |
+
settings_fields( $form['id'] );
|
511 |
+
do_settings_sections( $form['id'] );
|
512 |
+
do_action( 'wsa_form_bottom_' . $form['id'], $form );
|
513 |
+
if ( isset( $this->settings_fields[ $form['id'] ] ) ):
|
514 |
+
?>
|
515 |
+
<div style="padding-left: 10px">
|
516 |
+
<?php submit_button(); ?>
|
517 |
+
</div>
|
518 |
+
<?php endif; ?>
|
519 |
+
</form>
|
520 |
+
</div>
|
521 |
+
<?php } ?>
|
522 |
+
</div>
|
523 |
+
<?php
|
524 |
+
$this->script();
|
525 |
+
}
|
526 |
+
|
527 |
+
/**
|
528 |
+
* Tabbable JavaScript codes & Initiate Color Picker
|
529 |
+
*
|
530 |
+
* This code uses localstorage for displaying active tabs
|
531 |
+
*/
|
532 |
+
function script() {
|
533 |
+
?>
|
534 |
+
<script>
|
535 |
+
jQuery(document).ready(function($) {
|
536 |
+
//Initiate Color Picker
|
537 |
+
$('.wp-color-picker-field').wpColorPicker();
|
538 |
+
|
539 |
+
// Switches option sections
|
540 |
+
$('.group').hide();
|
541 |
+
var activetab = '';
|
542 |
+
if (typeof(localStorage) != 'undefined' ) {
|
543 |
+
activetab = localStorage.getItem("activetab");
|
544 |
+
}
|
545 |
+
if (activetab != '' && $(activetab).length ) {
|
546 |
+
$(activetab).fadeIn();
|
547 |
+
} else {
|
548 |
+
$('.group:first').fadeIn();
|
549 |
+
}
|
550 |
+
$('.group .collapsed').each(function(){
|
551 |
+
$(this).find('input:checked').parent().parent().parent().nextAll().each(
|
552 |
+
function(){
|
553 |
+
if ($(this).hasClass('last')) {
|
554 |
+
$(this).removeClass('hidden');
|
555 |
+
return false;
|
556 |
+
}
|
557 |
+
$(this).filter('.hidden').removeClass('hidden');
|
558 |
+
});
|
559 |
+
});
|
560 |
+
|
561 |
+
if (activetab != '' && $(activetab + '-tab').length ) {
|
562 |
+
$(activetab + '-tab').addClass('nav-tab-active');
|
563 |
+
}
|
564 |
+
else {
|
565 |
+
$('.nav-tab-wrapper a:first').addClass('nav-tab-active');
|
566 |
+
}
|
567 |
+
$('.nav-tab-wrapper a').click(function(evt) {
|
568 |
+
$('.nav-tab-wrapper a').removeClass('nav-tab-active');
|
569 |
+
$(this).addClass('nav-tab-active').blur();
|
570 |
+
var clicked_group = $(this).attr('href');
|
571 |
+
if (typeof(localStorage) != 'undefined' ) {
|
572 |
+
localStorage.setItem("activetab", $(this).attr('href'));
|
573 |
+
}
|
574 |
+
$('.group').hide();
|
575 |
+
$(clicked_group).fadeIn();
|
576 |
+
evt.preventDefault();
|
577 |
+
});
|
578 |
+
|
579 |
+
$('.wpsa-browse').on('click', function (event) {
|
580 |
+
event.preventDefault();
|
581 |
+
|
582 |
+
var self = $(this);
|
583 |
+
|
584 |
+
// Create the media frame.
|
585 |
+
var file_frame = wp.media.frames.file_frame = wp.media({
|
586 |
+
title: self.data('uploader_title'),
|
587 |
+
button: {
|
588 |
+
text: self.data('uploader_button_text'),
|
589 |
+
},
|
590 |
+
multiple: false
|
591 |
+
});
|
592 |
+
|
593 |
+
file_frame.on('select', function () {
|
594 |
+
attachment = file_frame.state().get('selection').first().toJSON();
|
595 |
+
self.prev('.wpsa-url').val(attachment.url).change();
|
596 |
+
});
|
597 |
+
|
598 |
+
// Finally, open the modal
|
599 |
+
file_frame.open();
|
600 |
+
});
|
601 |
+
});
|
602 |
+
</script>
|
603 |
+
<?php
|
604 |
+
$this->_style_fix();
|
605 |
+
}
|
606 |
+
|
607 |
+
function _style_fix() {
|
608 |
+
global $wp_version;
|
609 |
+
|
610 |
+
if (version_compare($wp_version, '3.8', '<=')):
|
611 |
+
?>
|
612 |
+
<style type="text/css">
|
613 |
+
/** WordPress 3.8 Fix **/
|
614 |
+
.form-table th { padding: 20px 10px; }
|
615 |
+
#wpbody-content .metabox-holder { padding-top: 5px; }
|
616 |
+
</style>
|
617 |
+
<?php
|
618 |
+
endif;
|
619 |
+
}
|
620 |
+
|
621 |
+
}
|
622 |
+
|
623 |
+
endif;
|
classes/class-setup.php
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* WordPress Heade and Footer Setup
|
5 |
+
*/
|
6 |
+
if ( !class_exists('WPHeaderAndFooter_Setting' ) ):
|
7 |
+
class WPHeaderAndFooter_Setting {
|
8 |
+
|
9 |
+
private $settings_api;
|
10 |
+
|
11 |
+
function __construct() {
|
12 |
+
|
13 |
+
include_once( WPHEADERANDFOOTER_DIR_PATH . 'classes/class-settings-api.php' );
|
14 |
+
$this->settings_api = new WPHeaderAndFooter_Settings_API;
|
15 |
+
|
16 |
+
add_action( 'admin_init', array($this, 'admin_init') );
|
17 |
+
add_action( 'admin_menu', array($this, 'register_options_page') );
|
18 |
+
}
|
19 |
+
|
20 |
+
function admin_init() {
|
21 |
+
|
22 |
+
//set the settings
|
23 |
+
$this->settings_api->set_sections( $this->get_settings_sections() );
|
24 |
+
$this->settings_api->set_fields( $this->get_settings_fields() );
|
25 |
+
|
26 |
+
//initialize settings
|
27 |
+
$this->settings_api->admin_init();
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Register the plugin settings panel
|
32 |
+
*/
|
33 |
+
function register_options_page() {
|
34 |
+
|
35 |
+
add_submenu_page( 'options-general.php', __( 'WP Headers and Footers', 'wp-header-and-footer' ), __( 'WP Headers and Footers', 'wp-header-and-footer' ), 'manage_options', 'wp-header-and-footer', array( $this, 'wp_header_and_footer_callback' ) );
|
36 |
+
}
|
37 |
+
|
38 |
+
function get_settings_sections() {
|
39 |
+
$sections = array(
|
40 |
+
array(
|
41 |
+
'id' => 'wpheaderandfooter_basics',
|
42 |
+
'title' => __( 'Settings', 'wp-header-and-footer' ),
|
43 |
+
'desc' => __( 'WP Headers and Footers.', 'wp-header-and-footer' ),
|
44 |
+
)
|
45 |
+
);
|
46 |
+
return $sections;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Returns all the settings fields
|
51 |
+
*
|
52 |
+
* @return array settings fields
|
53 |
+
*/
|
54 |
+
function get_settings_fields() {
|
55 |
+
$settings_fields = array(
|
56 |
+
'wpheaderandfooter_basics' => array(
|
57 |
+
array(
|
58 |
+
'name' => 'wp_header_textarea',
|
59 |
+
'label' => __( 'Scripts in Header', 'wp-header-and-footer' ),
|
60 |
+
'desc' => sprintf( __( 'These scripts will be printed in the %1$s%2$s%3$s section.', 'wp-header-and-footer' ), '<', 'head' ,'>' ),
|
61 |
+
'type' => 'textarea'
|
62 |
+
),
|
63 |
+
array(
|
64 |
+
'name' => 'wp_footer_textarea',
|
65 |
+
'label' => __( 'Scripts in Footer', 'wp-header-and-footer' ),
|
66 |
+
'desc' => sprintf( __( 'These scripts will be printed above the %1$s%2$s%3$s tag.', 'wp-header-and-footer' ), '<', '/body' ,'>'),
|
67 |
+
'type' => 'textarea'
|
68 |
+
)
|
69 |
+
)
|
70 |
+
);
|
71 |
+
|
72 |
+
return $settings_fields;
|
73 |
+
}
|
74 |
+
|
75 |
+
function wp_header_and_footer_callback() {
|
76 |
+
echo '<div class="wrap wp-header-and-footer">';
|
77 |
+
|
78 |
+
$this->settings_api->show_navigation();
|
79 |
+
$this->settings_api->show_forms();
|
80 |
+
|
81 |
+
echo '</div>';
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Get all the pages
|
86 |
+
*
|
87 |
+
* @return array page names with key value pairs
|
88 |
+
*/
|
89 |
+
function get_pages() {
|
90 |
+
$pages = get_pages();
|
91 |
+
$pages_options = array();
|
92 |
+
if ( $pages ) {
|
93 |
+
foreach ($pages as $page) {
|
94 |
+
$pages_options[$page->ID] = $page->post_title;
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
return $pages_options;
|
99 |
+
}
|
100 |
+
|
101 |
+
}
|
102 |
+
endif;
|
readme.txt
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== WordPress Headers and Footers ===
|
2 |
+
Contributors: WPBrigade
|
3 |
+
Tags: header script, add footer script, insert header code, add script headers and footers,
|
4 |
+
Requires at least: 3.0
|
5 |
+
Tested up to: 4.9
|
6 |
+
Stable tag: 1.0.0
|
7 |
+
License: GPLv3 or later
|
8 |
+
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
+
|
10 |
+
Include inline javascript, stylesheets, CSS code or anything you want in Header and Footer areas of your WordPress with ease.
|
11 |
+
|
12 |
+
== Description ==
|
13 |
+
|
14 |
+
This is a simple plugin to add inline javascript, stylesheets, CSS code or anything you want in Header and Footer areas of your WordPress with ease.
|
15 |
+
|
16 |
+
It helps for WordPress users to add a JS/CSS code directly in their site without touching their themes.
|
17 |
+
|
18 |
+
== Installation ==
|
19 |
+
|
20 |
+
This section describes how to install the WP Headers and Footers plugin and get it working.
|
21 |
+
|
22 |
+
= 1) Install =
|
23 |
+
|
24 |
+
1. Go to the WordPress Dashboard "Add New Plugin" section.
|
25 |
+
2. Search For "WP Headers and Footers plugin".
|
26 |
+
3. Install, then Activate it.
|
27 |
+
|
28 |
+
= 2) Configure =
|
29 |
+
1. Reach out to the Settings->WP Headers and Footers Page
|
30 |
+
|
31 |
+
|
32 |
+
== Frequently Asked Questions ==
|
33 |
+
|
34 |
+
|
35 |
+
= Why this plugin is needed ? =
|
36 |
+
It helps for WordPress users to add a JS/CSS code directly in their site without touching their themes.
|
37 |
+
|
38 |
+
|
39 |
+
== Screenshots ==
|
40 |
+
|
41 |
+
1. Add Headers and Footers code in Settings Panel.
|
42 |
+
|
43 |
+
|
44 |
+
== Changelog ==
|
45 |
+
|
46 |
+
= 1.0.0 =
|
47 |
+
* Initial Release.
|
48 |
+
|
49 |
+
|
50 |
+
== Upgrade Notice ==
|
51 |
+
|
52 |
+
= 1.0.0 =
|
53 |
+
* Initial release.
|
wp-headers-and-footers.php
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Plugin Name: WP Headers and Footers
|
4 |
+
* Plugin URI: http://www.WPBrigade.com/wordpress/plugins/wp-headers-and-footers/
|
5 |
+
* Description: Allows you to insert code or text in the header or footer of your WordPress site.
|
6 |
+
* Version: 1.0.0
|
7 |
+
* Author: WPBrigade
|
8 |
+
* Author URI: https://www.WPBrigade.com/
|
9 |
+
* License: GPLv3
|
10 |
+
* Text Domain: wp-headers-and-footers
|
11 |
+
* Domain Path: /languages
|
12 |
+
*
|
13 |
+
* @package wp-headers-and-footers
|
14 |
+
* @category Core
|
15 |
+
* @author WPBrigade
|
16 |
+
*/
|
17 |
+
|
18 |
+
|
19 |
+
if ( ! class_exists( 'WPHeaderAndFooter' ) ) :
|
20 |
+
|
21 |
+
final class WPHeaderAndFooter {
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @var string
|
25 |
+
*/
|
26 |
+
public $version = '1.0.0';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @var The single instance of the class
|
30 |
+
* @since 1.0.0
|
31 |
+
*/
|
32 |
+
|
33 |
+
protected static $_instance = null;
|
34 |
+
|
35 |
+
/* * * * * * * * * *
|
36 |
+
* Class constructor
|
37 |
+
* * * * * * * * * */
|
38 |
+
public function __construct() {
|
39 |
+
|
40 |
+
$this->define_constants();
|
41 |
+
$this->includes();
|
42 |
+
$this->_hooks();
|
43 |
+
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Include required core files used in admin and on the frontend.
|
48 |
+
*/
|
49 |
+
|
50 |
+
public function includes() {
|
51 |
+
|
52 |
+
include_once( WPHEADERANDFOOTER_DIR_PATH . 'classes/class-setup.php' );
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Hook into actions and filters
|
57 |
+
* @since 1.0.0
|
58 |
+
*/
|
59 |
+
private function _hooks() {
|
60 |
+
|
61 |
+
add_action( 'plugins_loaded', array( $this, 'textdomain' ) );
|
62 |
+
add_action( 'admin_enqueue_scripts', array( $this, '_admin_scripts' ) );
|
63 |
+
add_action( 'wp_head', array( $this, 'frontendHeader' ) );
|
64 |
+
add_action( 'wp_footer', array( $this, 'frontendFooter' ) );
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Define WP Header and Footer Constants
|
69 |
+
*/
|
70 |
+
private function define_constants() {
|
71 |
+
|
72 |
+
$this->define( 'WPHEADERANDFOOTER_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
73 |
+
$this->define( 'WPHEADERANDFOOTER_DIR_PATH', plugin_dir_path( __FILE__ ) );
|
74 |
+
$this->define( 'WPHEADERANDFOOTER_DIR_URL', plugin_dir_url( __FILE__ ) );
|
75 |
+
$this->define( 'WPHEADERANDFOOTER_ROOT_PATH', dirname( __FILE__ ) . '/' );
|
76 |
+
$this->define( 'WPHEADERANDFOOTER_VERSION', $this->version );
|
77 |
+
$this->define( 'WPHEADERANDFOOTER_FEEDBACK_SERVER', 'https://wpbrigade.com/' );
|
78 |
+
}
|
79 |
+
|
80 |
+
function _admin_scripts() {
|
81 |
+
wp_enqueue_style( 'wpheaderandfooter_stlye', plugins_url( 'asset/css/style.css', __FILE__ ), array(), WPHEADERANDFOOTER_VERSION );
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Define constant if not already set
|
86 |
+
* @param string $name
|
87 |
+
* @param string|bool $value
|
88 |
+
*/
|
89 |
+
private function define( $name, $value ) {
|
90 |
+
if ( ! defined( $name ) ) {
|
91 |
+
define( $name, $value );
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Main Instance
|
97 |
+
*
|
98 |
+
* @since 1.0.0
|
99 |
+
* @static
|
100 |
+
* @see wpheaderandfooter_loader()
|
101 |
+
* @return Main instance
|
102 |
+
*/
|
103 |
+
public static function instance() {
|
104 |
+
if ( is_null( self::$_instance ) ) {
|
105 |
+
self::$_instance = new self();
|
106 |
+
}
|
107 |
+
return self::$_instance;
|
108 |
+
}
|
109 |
+
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Load Languages
|
113 |
+
* @since 1.0.0
|
114 |
+
*/
|
115 |
+
public function textdomain() {
|
116 |
+
|
117 |
+
$plugin_dir = dirname( plugin_basename( __FILE__ ) ) ;
|
118 |
+
load_plugin_textdomain( 'wp-headers-and-footers', false, $plugin_dir . '/languages/' );
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Outputs script / CSS to the header
|
123 |
+
*/
|
124 |
+
function frontendHeader() {
|
125 |
+
$this->_output( 'wp_header_textarea' );
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Outputs script / CSS to the footer
|
130 |
+
*/
|
131 |
+
function frontendFooter() {
|
132 |
+
$this->_output( 'wp_footer_textarea' );
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Outputs the given setting, if conditions are met
|
137 |
+
*
|
138 |
+
* @param string $script Setting Name
|
139 |
+
* @return output
|
140 |
+
*/
|
141 |
+
function _output( $script ) {
|
142 |
+
|
143 |
+
// Ignore admin, feed, robots or trackbacks
|
144 |
+
if ( is_admin() || is_feed() || is_robots() || is_trackback() ) :
|
145 |
+
return;
|
146 |
+
endif;
|
147 |
+
|
148 |
+
// Get meta
|
149 |
+
$_wphaf_setting = get_option( 'wpheaderandfooter_basics' );
|
150 |
+
$meta = ! empty ( $_wphaf_setting[$script] ) ? $_wphaf_setting[$script] : false;
|
151 |
+
|
152 |
+
if ( trim( $meta ) == '' || ! $meta ) :
|
153 |
+
return;
|
154 |
+
endif;
|
155 |
+
|
156 |
+
// Output
|
157 |
+
echo wp_unslash( $meta );
|
158 |
+
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
endif;
|
163 |
+
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Returns the main instance of WP to prevent the need to use globals.
|
167 |
+
*
|
168 |
+
* @since 1.0.0
|
169 |
+
* @return WPHeaderAndFooter
|
170 |
+
*/
|
171 |
+
function wpheaderandfooter_loader() {
|
172 |
+
return WPHeaderAndFooter::instance();
|
173 |
+
}
|
174 |
+
|
175 |
+
// Call the function
|
176 |
+
wpheaderandfooter_loader();
|
177 |
+
new WPHeaderAndFooter_Setting();
|