|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Auto Load Next Post: Theme Customizer |
|
4
|
|
|
* |
|
5
|
|
|
* @since 1.5.0 |
|
6
|
|
|
* @version 1.6.0 |
|
7
|
|
|
* @author Sébastien Dumont |
|
8
|
|
|
* @category Classes |
|
9
|
|
|
* @package Auto Load Next Post/Classes/Customizer |
|
10
|
|
|
* @license GPL-2.0+ |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
// Exit if accessed directly. |
|
14
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
15
|
|
|
exit; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
if ( ! class_exists( 'ALNP_Customizer' ) ) { |
|
19
|
|
|
|
|
20
|
|
|
class ALNP_Customizer { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @access public |
|
26
|
|
|
* @since 1.5.0 |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct() { |
|
29
|
|
|
add_action( 'customize_register', array( $this, 'alnp_init_customizer' ), 50 ); |
|
30
|
|
|
add_filter( 'customize_loaded_components', array( $this, 'alnp_remove_widgets_panel' ) ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Initialize the Customizer. |
|
35
|
|
|
* |
|
36
|
|
|
* @access public |
|
37
|
|
|
* @since 1.5.0 |
|
38
|
|
|
* @param WP_Customize_Manager $wp_customize The Customizer object. |
|
39
|
|
|
*/ |
|
40
|
|
|
public function alnp_init_customizer( $wp_customize ) { |
|
41
|
|
|
/** |
|
42
|
|
|
* Dont add settings to the customizer if the user does |
|
43
|
|
|
* not have permission to make changes to the theme. |
|
44
|
|
|
*/ |
|
45
|
|
|
if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
46
|
|
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
// Load custom controllers. |
|
50
|
|
|
require_once( dirname( __FILE__ ) . '/class-alnp-arbitrary-controller.php' ); |
|
51
|
|
|
//require_once( dirname( __FILE__ ) . '/class-alnp-display-video-controller.php' ); |
|
52
|
|
|
|
|
53
|
|
|
// Auto Load Next Post Panel. |
|
54
|
|
|
$panel = array( 'panel' => 'alnp' ); |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Add the main panel and sections. |
|
58
|
|
|
* |
|
59
|
|
|
* Only shows if viewing a singular post. |
|
60
|
|
|
*/ |
|
61
|
|
|
$wp_customize->add_panel( |
|
62
|
|
|
'alnp', array( |
|
63
|
|
|
'title' => esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ), |
|
64
|
|
|
'capability' => 'edit_theme_options', |
|
65
|
|
|
'description' => sprintf( esc_html__( '%s increases your pageviews by engaging the site viewers to keep reading your content rather than increasing your bounce rate.', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ), |
|
66
|
|
|
'priority' => 160, |
|
67
|
|
|
'active_callback' => array( $this, 'is_page_alnp_ready' ) |
|
68
|
|
|
) |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
// Get the sections. |
|
72
|
|
|
$sections = $this->alnp_get_customizer_sections(); |
|
73
|
|
|
|
|
74
|
|
|
// Add each section. |
|
75
|
|
|
foreach ( $sections as $section => $args ) { |
|
76
|
|
|
/** |
|
77
|
|
|
* If we are not only viewing Auto Load Next Post customizer sections |
|
78
|
|
|
* then move them under our own panel. |
|
79
|
|
|
*/ |
|
80
|
|
|
if ( ! $this->alnp_is_customizer() ) { |
|
81
|
|
|
$args = array_merge( $args, $panel ); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$wp_customize->add_section( $section, $args ); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
// Get plugin settings. |
|
88
|
|
|
$settings = $this->alnp_get_customizer_settings(); |
|
89
|
|
|
|
|
90
|
|
|
// Add each setting. |
|
91
|
|
|
foreach ( $settings as $setting => $args ) { |
|
92
|
|
|
$wp_customize->add_setting( $setting, $args ); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Let other plugins register extra customizer options for Auto Load Next Post. |
|
97
|
|
|
* |
|
98
|
|
|
* @since 1.5.0 |
|
99
|
|
|
* @param WP_Customize_Manager $wp_customize The Customizer object. |
|
100
|
|
|
*/ |
|
101
|
|
|
do_action( 'alnp_customizer_register', $wp_customize ); |
|
102
|
|
|
|
|
103
|
|
|
$controls = $this->alnp_get_customizer_controls(); |
|
104
|
|
|
|
|
105
|
|
|
foreach ( $controls as $control => $args ) { |
|
106
|
|
|
$wp_customize->add_control( new $args['class']( $wp_customize, $control, $args ) ); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
if ( $this->alnp_is_customizer() ) { |
|
110
|
|
|
$this->alnp_remove_default_customizer_panels( $wp_customize ); // Remove controls from the customizer. |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
// Video Help - Coming Soon |
|
114
|
|
|
/*$wp_customize->add_setting( 'alnp_video_theme_selectors', array( |
|
115
|
|
|
'default' => '', // The video ID |
|
116
|
|
|
'type' => 'theme_mod', |
|
117
|
|
|
) ); |
|
118
|
|
|
|
|
119
|
|
|
$wp_customize->add_control( new ALNP_Display_Video_Controller( $wp_customize, 'alnp_video_theme_selectors', array( |
|
120
|
|
|
'label' => __( 'Video: How to find your theme selectors', 'auto-load-next-post' ), |
|
121
|
|
|
'section' => 'auto_load_next_post_theme_selectors', |
|
122
|
|
|
'settings' => 'alnp_video_theme_selectors', |
|
123
|
|
|
'type' => 'alnp-display-video', |
|
124
|
|
|
'priority' => 1, |
|
125
|
|
|
) ) );*/ |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* If Auto Load Next Post Pro is not installed, display a new section |
|
129
|
|
|
* to tell users about the pro version, what comes with it |
|
130
|
|
|
* and link to product page. |
|
131
|
|
|
*/ |
|
132
|
|
|
if ( ! is_alnp_pro_version_installed() ) { |
|
133
|
|
|
include_once( dirname( __FILE__ ) . '/class-alnp-pro-preview-controller.php' ); |
|
134
|
|
|
|
|
135
|
|
|
$preview_args = array( |
|
136
|
|
|
'title' => esc_html__( 'More?', 'auto-load-next-post' ), |
|
137
|
|
|
'priority' => 999, |
|
138
|
|
|
); |
|
139
|
|
|
|
|
140
|
|
|
if ( ! $this->alnp_is_customizer() ) { |
|
141
|
|
|
$preview_args = array_merge( $preview_args, $panel ); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
$wp_customize->add_section( 'alnp_pro_preview', $preview_args ); |
|
145
|
|
|
|
|
146
|
|
|
$wp_customize->add_setting( 'alnp_pro_preview', array( |
|
147
|
|
|
'default' => null, |
|
148
|
|
|
) ); |
|
149
|
|
|
|
|
150
|
|
|
$wp_customize->add_control( new ALNP_Pro_Preview_Controller( $wp_customize, 'alnp_pro_preview', array( |
|
151
|
|
|
'label' => __( 'Looking for more options?', 'auto-load-next-post' ), |
|
152
|
|
|
'section' => 'alnp_pro_preview', |
|
153
|
|
|
'settings' => 'alnp_pro_preview', |
|
154
|
|
|
'priority' => 1, |
|
155
|
|
|
) ) ); |
|
156
|
|
|
} |
|
157
|
|
|
} // END alnp_init_customizer() |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Removes the core 'Navigation Menu' and 'Widgets' panel from the Customizer. |
|
161
|
|
|
* |
|
162
|
|
|
* @access public |
|
163
|
|
|
* @since 1.5.0 |
|
164
|
|
|
* @param array $components Core Customizer components list. |
|
165
|
|
|
* @return array (Maybe) modified components list. |
|
166
|
|
|
*/ |
|
167
|
|
|
public function alnp_remove_widgets_panel( $components ) { |
|
168
|
|
|
if ( $this->alnp_is_customizer() ) { |
|
169
|
|
|
foreach( $components as $key => $component ) { |
|
170
|
|
|
if ( $component == 'widgets' ) { |
|
171
|
|
|
unset( $components[ 'widgets' ] ); |
|
172
|
|
|
} |
|
173
|
|
|
if ( $component == 'nav_menus' ) { |
|
174
|
|
|
unset( $components[ 'nav_menus' ] ); |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
return $components; |
|
180
|
|
|
} // END alnp_remove_widgets_panel() |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Remove any unwanted default conrols. |
|
184
|
|
|
* |
|
185
|
|
|
* @access public |
|
186
|
|
|
* @since 1.5.0 |
|
187
|
|
|
* @global $wp_cutomize |
|
188
|
|
|
* @param object $wp_customize |
|
189
|
|
|
* @return boolean |
|
190
|
|
|
*/ |
|
191
|
|
|
public function alnp_remove_default_customizer_panels( $wp_customize ) { |
|
192
|
|
|
global $wp_customize; |
|
193
|
|
|
|
|
194
|
|
|
$wp_customize->remove_section("themes"); |
|
195
|
|
|
$wp_customize->remove_control("active_theme"); |
|
196
|
|
|
$wp_customize->remove_section("title_tagline"); |
|
197
|
|
|
$wp_customize->remove_section("colors"); |
|
198
|
|
|
$wp_customize->remove_section("header_image"); |
|
199
|
|
|
$wp_customize->remove_section("background_image"); |
|
200
|
|
|
$wp_customize->remove_section("static_front_page"); |
|
201
|
|
|
$wp_customize->remove_section("custom_css"); |
|
202
|
|
|
$wp_customize->remove_section("theme_options"); |
|
203
|
|
|
|
|
204
|
|
|
return true; |
|
205
|
|
|
} // END alnp_remove_default_customizer_panels() |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Are we looking at the Auto Load Next Post customizer? |
|
209
|
|
|
* |
|
210
|
|
|
* @access public |
|
211
|
|
|
* @since 1.5.0 |
|
212
|
|
|
* @return boolean |
|
213
|
|
|
*/ |
|
214
|
|
|
public function alnp_is_customizer() { |
|
215
|
|
|
return isset( $_GET['alnp-customizer'] ) && $_GET['alnp-customizer'] === 'yes'; |
|
216
|
|
|
} // END alnp_is_customizer() |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Get Customizer sections for Auto Load Next Post. |
|
220
|
|
|
* |
|
221
|
|
|
* @access public |
|
222
|
|
|
* @since 1.5.0 |
|
223
|
|
|
* @return array |
|
224
|
|
|
*/ |
|
225
|
|
|
public function alnp_get_customizer_sections() { |
|
226
|
|
|
/** |
|
227
|
|
|
* Filter Customizer sections for Auto Load Next Post. |
|
228
|
|
|
* |
|
229
|
|
|
* @param array $sections Customizer sections to add. |
|
230
|
|
|
*/ |
|
231
|
|
|
return apply_filters( 'alnp_get_customizer_sections', array( |
|
232
|
|
|
'auto_load_next_post_theme_selectors' => array( |
|
233
|
|
|
'capability' => 'edit_theme_options', |
|
234
|
|
|
'title' => esc_html__( 'Theme Selectors', 'auto-load-next-post' ), |
|
235
|
|
|
'description' => sprintf( __( 'Set the theme selectors below according to the theme. %1$sHow to find my theme selectors?%2$s', 'auto-load-next-post' ), '<a href="' . esc_url( 'https://github.com/autoloadnextpost/alnp-documentation/blob/master/en_US/theme-selectors.md#how-to-find-your-theme-selectors' ) . '" target="_blank">', '</a>' ), |
|
236
|
|
|
), |
|
237
|
|
|
'auto_load_next_post_misc' => array( |
|
238
|
|
|
'capability' => 'edit_theme_options', |
|
239
|
|
|
'title' => esc_html__( 'Misc Settings', 'auto-load-next-post' ), |
|
240
|
|
|
'description' => sprintf( __( 'Here you can set if you want to track pageviews, remove comments and load %s javascript in the footer and disable for mobile users.', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ), |
|
241
|
|
|
), |
|
242
|
|
|
'auto_load_next_post_events' => array( |
|
243
|
|
|
'capability' => 'edit_theme_options', |
|
244
|
|
|
'title' => esc_html__( 'Events', 'auto-load-next-post' ), |
|
245
|
|
|
'description' => sprintf( __( 'Below you can enter external JavaScript events to be triggered alongside %1$s native events. Separate each event like so: %2$s', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ), '<code>event1, event2,</code>' ), |
|
246
|
|
|
), |
|
247
|
|
|
) ); |
|
248
|
|
|
} // END alnp_get_customizer_sections() |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Get Customizer settings for Auto Load Next Post. |
|
252
|
|
|
* |
|
253
|
|
|
* @access public |
|
254
|
|
|
* @since 1.5.0 |
|
255
|
|
|
* @version 1.6.0 |
|
256
|
|
|
* @return array |
|
257
|
|
|
*/ |
|
258
|
|
|
public function alnp_get_customizer_settings() { |
|
259
|
|
|
$settings = $this->alnp_get_settings(); |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Filter Customizer settings for Auto Load Next Post. |
|
263
|
|
|
* |
|
264
|
|
|
* @param array $settings Customizer settings to add. |
|
265
|
|
|
*/ |
|
266
|
|
|
return apply_filters( 'alnp_get_customizer_settings', array( |
|
267
|
|
|
'auto_load_next_post_content_container' => array( |
|
268
|
|
|
'capability' => 'edit_theme_options', |
|
269
|
|
|
'default' => $settings['alnp_content_container'], |
|
270
|
|
|
'sanitize_callback' => 'wp_filter_post_kses', |
|
271
|
|
|
'validate_callback' => array( $this, 'alnp_validate_content_container_selector' ), |
|
272
|
|
|
'transport' => 'postMessage', |
|
273
|
|
|
'type' => 'option', |
|
274
|
|
|
), |
|
275
|
|
|
'auto_load_next_post_title_selector' => array( |
|
276
|
|
|
'capability' => 'edit_theme_options', |
|
277
|
|
|
'default' => $settings['alnp_title_selector'], |
|
278
|
|
|
'sanitize_callback' => 'wp_filter_post_kses', |
|
279
|
|
|
'validate_callback' => array( $this, 'alnp_validate_post_title_selector' ), |
|
280
|
|
|
'transport' => 'postMessage', |
|
281
|
|
|
'type' => 'option', |
|
282
|
|
|
), |
|
283
|
|
|
'auto_load_next_post_navigation_container' => array( |
|
284
|
|
|
'capability' => 'edit_theme_options', |
|
285
|
|
|
'default' => $settings['alnp_navigation_container'], |
|
286
|
|
|
'sanitize_callback' => 'wp_filter_post_kses', |
|
287
|
|
|
'validate_callback' => array( $this, 'alnp_validate_post_navigation_selector' ), |
|
288
|
|
|
'transport' => 'postMessage', |
|
289
|
|
|
'type' => 'option', |
|
290
|
|
|
), |
|
291
|
|
|
'auto_load_next_post_previous_post_selector' => array( |
|
292
|
|
|
'capability' => 'edit_theme_options', |
|
293
|
|
|
'default' => $settings['alnp_previous_post_selector'], |
|
294
|
|
|
'sanitize_callback' => 'wp_filter_post_kses', |
|
295
|
|
|
'transport' => 'postMessage', |
|
296
|
|
|
'type' => 'option', |
|
297
|
|
|
), |
|
298
|
|
|
'auto_load_next_post_comments_container' => array( |
|
299
|
|
|
'capability' => 'edit_theme_options', |
|
300
|
|
|
'default' => $settings['alnp_comments_container'], |
|
301
|
|
|
'sanitize_callback' => 'wp_filter_post_kses', |
|
302
|
|
|
'transport' => 'postMessage', |
|
303
|
|
|
'type' => 'option', |
|
304
|
|
|
), |
|
305
|
|
|
'auto_load_next_post_remove_comments' => array( |
|
306
|
|
|
'capability' => 'edit_theme_options', |
|
307
|
|
|
'sanitize_callback' => array( $this, 'sanitize_checkbox' ), |
|
308
|
|
|
'default' => 'yes', |
|
309
|
|
|
'transport' => 'refresh', |
|
310
|
|
|
'type' => 'option', |
|
311
|
|
|
), |
|
312
|
|
|
'auto_load_next_post_google_analytics' => array( |
|
313
|
|
|
'capability' => 'edit_theme_options', |
|
314
|
|
|
'sanitize_callback' => array( $this, 'sanitize_checkbox' ), |
|
315
|
|
|
'default' => 'no', |
|
316
|
|
|
'transport' => 'refresh', |
|
317
|
|
|
'type' => 'option', |
|
318
|
|
|
), |
|
319
|
|
|
'auto_load_next_post_load_js_in_footer' => array( |
|
320
|
|
|
'capability' => 'edit_theme_options', |
|
321
|
|
|
'sanitize_callback' => array( $this, 'sanitize_checkbox' ), |
|
322
|
|
|
'default' => 'no', |
|
323
|
|
|
'transport' => 'refresh', |
|
324
|
|
|
'type' => 'option', |
|
325
|
|
|
), |
|
326
|
|
|
'auto_load_next_post_disable_on_mobile' => array( |
|
327
|
|
|
'capability' => 'edit_theme_options', |
|
328
|
|
|
'sanitize_callback' => array( $this, 'sanitize_checkbox' ), |
|
329
|
|
|
'default' => 'no', |
|
330
|
|
|
'type' => 'option', |
|
331
|
|
|
'transport' => 'refresh', |
|
332
|
|
|
), |
|
333
|
|
|
'auto_load_next_post_on_load_event' => array( |
|
334
|
|
|
'capability' => 'edit_theme_options', |
|
335
|
|
|
'default' => $settings['alnp_on_load_event'], |
|
336
|
|
|
'transport' => 'postMessage', |
|
337
|
|
|
'type' => 'option', |
|
338
|
|
|
), |
|
339
|
|
|
'auto_load_next_post_on_entering_event' => array( |
|
340
|
|
|
'capability' => 'edit_theme_options', |
|
341
|
|
|
'default' => $settings['alnp_on_entering_event'], |
|
342
|
|
|
'transport' => 'postMessage', |
|
343
|
|
|
'type' => 'option', |
|
344
|
|
|
), |
|
345
|
|
|
) ); |
|
346
|
|
|
} // END alnp_get_customizer_settings() |
|
347
|
|
|
|
|
348
|
|
|
/** |
|
349
|
|
|
* Get Customizer controls for Auto Load Next Post. |
|
350
|
|
|
* |
|
351
|
|
|
* @access public |
|
352
|
|
|
* @since 1.5.0 |
|
353
|
|
|
* @version 1.6.0 |
|
354
|
|
|
* @return array |
|
355
|
|
|
*/ |
|
356
|
|
|
public function alnp_get_customizer_controls() { |
|
357
|
|
|
/** |
|
358
|
|
|
* Filter Customizer controls for Auto Load Next Post. |
|
359
|
|
|
* |
|
360
|
|
|
* @param array $controls Customizer controls to add. |
|
361
|
|
|
*/ |
|
362
|
|
|
return apply_filters( 'alnp_get_customizer_controls', array( |
|
363
|
|
|
'alnp_content_container' => array( |
|
364
|
|
|
'class' => 'WP_Customize_Control', |
|
365
|
|
|
'label' => esc_html__( 'Content Container', 'auto-load-next-post' ), |
|
366
|
|
|
'description' => sprintf( __( 'The primary container where the post content is loaded in. Default: %s', 'auto-load-next-post' ), '<code>main.site-main</code>' ), |
|
367
|
|
|
'section' => 'auto_load_next_post_theme_selectors', |
|
368
|
|
|
'settings' => 'auto_load_next_post_content_container', |
|
369
|
|
|
'type' => 'text', |
|
370
|
|
|
), |
|
371
|
|
|
'alnp_title_selector' => array( |
|
372
|
|
|
'class' => 'WP_Customize_Control', |
|
373
|
|
|
'label' => esc_html__( 'Post Title Selector', 'auto-load-next-post' ), |
|
374
|
|
|
'description' => sprintf( __( 'Used to identify which article the user is reading and track should Google Analytics or other analytics be enabled. Default: %s', 'auto-load-next-post' ), '<code>h1.entry-title</code>' ), |
|
375
|
|
|
'section' => 'auto_load_next_post_theme_selectors', |
|
376
|
|
|
'settings' => 'auto_load_next_post_title_selector', |
|
377
|
|
|
'type' => 'text', |
|
378
|
|
|
), |
|
379
|
|
|
'alnp_navigation_container' => array( |
|
380
|
|
|
'class' => 'WP_Customize_Control', |
|
381
|
|
|
'label' => esc_html__( 'Post Navigation Container', 'auto-load-next-post' ), |
|
382
|
|
|
'description' => sprintf( __( 'Used to identify which post to load next if any. Default: %s', 'auto-load-next-post' ), '<code>nav.post-navigation</code>' ), |
|
383
|
|
|
'section' => 'auto_load_next_post_theme_selectors', |
|
384
|
|
|
'settings' => 'auto_load_next_post_navigation_container', |
|
385
|
|
|
'type' => 'text', |
|
386
|
|
|
), |
|
387
|
|
|
'alnp_comments_container' => array( |
|
388
|
|
|
'class' => 'WP_Customize_Control', |
|
389
|
|
|
'label' => esc_html__( 'Comments Container', 'auto-load-next-post' ), |
|
390
|
|
|
'description' => sprintf( __( 'Used to remove comments if enabled under %1$sMisc%2$s settings. Default: %3$s', 'auto-load-next-post' ), '<strong><a href="javascript:wp.customize.section( \'auto_load_next_post_misc\' ).focus();">', '</a></strong>', '<code>div#comments</code>' ), |
|
391
|
|
|
'section' => 'auto_load_next_post_theme_selectors', |
|
392
|
|
|
'settings' => 'auto_load_next_post_comments_container', |
|
393
|
|
|
'type' => 'text', |
|
394
|
|
|
), |
|
395
|
|
|
'alnp_remove_comments' => array( |
|
396
|
|
|
'class' => 'WP_Customize_Control', |
|
397
|
|
|
'label' => esc_html__( 'Remove Comments', 'auto-load-next-post' ), |
|
398
|
|
|
'description' => esc_html__( 'Enable to remove comments when each post loads including the initial post.', 'auto-load-next-post' ), |
|
399
|
|
|
'section' => 'auto_load_next_post_misc', |
|
400
|
|
|
'settings' => 'auto_load_next_post_remove_comments', |
|
401
|
|
|
'type' => 'checkbox', |
|
402
|
|
|
), |
|
403
|
|
|
'alnp_google_analytics' => array( |
|
404
|
|
|
'class' => 'WP_Customize_Control', |
|
405
|
|
|
'label' => esc_html__( 'Update Google Analytics', 'auto-load-next-post' ), |
|
406
|
|
|
'description' => esc_html__( 'Enable to track each post the visitor is reading. This will count as a pageview. You must already have Google Analytics setup.', 'auto-load-next-post' ), |
|
407
|
|
|
'section' => 'auto_load_next_post_misc', |
|
408
|
|
|
'settings' => 'auto_load_next_post_google_analytics', |
|
409
|
|
|
'type' => 'checkbox', |
|
410
|
|
|
), |
|
411
|
|
|
'alnp_js_footer' => array( |
|
412
|
|
|
'class' => 'WP_Customize_Control', |
|
413
|
|
|
'label' => esc_html__( 'JavaScript in Footer?', 'auto-load-next-post' ), |
|
414
|
|
|
'description' => esc_html__( 'Enable to load Auto Load Next Post in the footer instead of the header. Can be useful to optimize your site.', 'auto-load-next-post' ), |
|
415
|
|
|
'section' => 'auto_load_next_post_misc', |
|
416
|
|
|
'settings' => 'auto_load_next_post_load_js_in_footer', |
|
417
|
|
|
'type' => 'checkbox', |
|
418
|
|
|
), |
|
419
|
|
|
'alnp_disable_on_mobile' => array( |
|
420
|
|
|
'class' => 'WP_Customize_Control', |
|
421
|
|
|
'label' => esc_html__( 'Disable for Mobile?', 'auto-load-next-post' ), |
|
422
|
|
|
'description' => sprintf( esc_html__( 'Enable to disable %s from running on mobile devices.', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ), |
|
423
|
|
|
'section' => 'auto_load_next_post_misc', |
|
424
|
|
|
'settings' => 'auto_load_next_post_disable_on_mobile', |
|
425
|
|
|
'type' => 'checkbox', |
|
426
|
|
|
), |
|
427
|
|
|
'alnp_on_load_event' => array( |
|
428
|
|
|
'class' => 'WP_Customize_Control', |
|
429
|
|
|
'label' => esc_html__( 'Post loaded', 'auto-load-next-post' ), |
|
430
|
|
|
'description' => esc_html__( 'Events listed here will be triggered after a new post has loaded.', 'auto-load-next-post' ), |
|
431
|
|
|
'section' => 'auto_load_next_post_events', |
|
432
|
|
|
'settings' => 'auto_load_next_post_on_load_event', |
|
433
|
|
|
'type' => 'textarea', |
|
434
|
|
|
), |
|
435
|
|
|
'alnp_on_entering_event' => array( |
|
436
|
|
|
'class' => 'WP_Customize_Control', |
|
437
|
|
|
'label' => esc_html__( 'Entering a Post', 'auto-load-next-post' ), |
|
438
|
|
|
'description' => esc_html__( 'Events listed here will be triggered when entering a post.', 'auto-load-next-post' ), |
|
439
|
|
|
'section' => 'auto_load_next_post_events', |
|
440
|
|
|
'settings' => 'auto_load_next_post_on_entering_event', |
|
441
|
|
|
'type' => 'textarea', |
|
442
|
|
|
), |
|
443
|
|
|
) ); |
|
444
|
|
|
} // END alnp_get_customizer_controls() |
|
445
|
|
|
|
|
446
|
|
|
/** |
|
447
|
|
|
* Validates the content container theme selector to not be empty. |
|
448
|
|
|
* |
|
449
|
|
|
* @access public |
|
450
|
|
|
* @since 1.5.0 |
|
451
|
|
|
* @param WP_Error $validity Validity. |
|
452
|
|
|
* @param string $value Value, normally pre-sanitized. |
|
453
|
|
|
* @return WP_Error $validity |
|
454
|
|
|
*/ |
|
455
|
|
|
public function alnp_validate_content_container_selector( $validity, $value ) { |
|
456
|
|
|
if ( empty( $value ) ) { |
|
457
|
|
|
$validity->add( 'required', esc_html__( 'The content container selector is empty. Will not know where to load posts without it.', 'auto-load-next-post' ) ); |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
|
|
return $validity; |
|
461
|
|
|
} // END alnp_validate_content_container_selector() |
|
462
|
|
|
|
|
463
|
|
|
/** |
|
464
|
|
|
* Validates the post title theme selector to not be empty. |
|
465
|
|
|
* |
|
466
|
|
|
* @access public |
|
467
|
|
|
* @since 1.5.0 |
|
468
|
|
|
* @param WP_Error $validity Validity. |
|
469
|
|
|
* @param string $value Value, normally pre-sanitized. |
|
470
|
|
|
* @return WP_Error $validity |
|
471
|
|
|
*/ |
|
472
|
|
|
public function alnp_validate_post_title_selector( $validity, $value ) { |
|
473
|
|
|
if ( empty( $value ) ) { |
|
474
|
|
|
$validity->add( 'required', esc_html__( 'The post title selector is empty. Will not be able to identify which article the user is reading.', 'auto-load-next-post' ) ); |
|
475
|
|
|
} |
|
476
|
|
|
|
|
477
|
|
|
return $validity; |
|
478
|
|
|
} // END alnp_validate_post_title_selector() |
|
479
|
|
|
|
|
480
|
|
|
/** |
|
481
|
|
|
* Validates the post navigation theme selector to not be empty. |
|
482
|
|
|
* |
|
483
|
|
|
* @access public |
|
484
|
|
|
* @since 1.5.0 |
|
485
|
|
|
* @param WP_Error $validity Validity. |
|
486
|
|
|
* @param string $value Value, normally pre-sanitized. |
|
487
|
|
|
* @return WP_Error $validity |
|
488
|
|
|
*/ |
|
489
|
|
|
public function alnp_validate_post_navigation_selector( $validity, $value ) { |
|
490
|
|
|
if ( empty( $value ) ) { |
|
491
|
|
|
$validity->add( 'required', esc_html__( 'The post navigation container selector is empty. Required so ALNP can look up the next post to load.', 'auto-load-next-post' ) ); |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
return $validity; |
|
495
|
|
|
} // END alnp_validate_post_navigation_selector() |
|
496
|
|
|
|
|
497
|
|
|
/** |
|
498
|
|
|
* Return Auto Load Next Post settings. |
|
499
|
|
|
* |
|
500
|
|
|
* @access public |
|
501
|
|
|
* @since 1.5.0 |
|
502
|
|
|
* @version 1.6.0 |
|
503
|
|
|
* @return array $args |
|
504
|
|
|
*/ |
|
505
|
|
|
public function alnp_get_settings() { |
|
506
|
|
|
$args = array( |
|
507
|
|
|
'alnp_content_container' => get_option( 'auto_load_next_post_content_container' ), |
|
508
|
|
|
'alnp_title_selector' => get_option( 'auto_load_next_post_title_selector' ), |
|
509
|
|
|
'alnp_navigation_container' => get_option( 'auto_load_next_post_navigation_container' ), |
|
510
|
|
|
'alnp_previous_post_selector' => get_option( 'auto_load_next_post_previous_post_selector' ), |
|
511
|
|
|
'alnp_comments_container' => get_option( 'auto_load_next_post_comments_container' ), |
|
512
|
|
|
'alnp_remove_comments' => get_option( 'auto_load_next_post_remove_comments' ), |
|
513
|
|
|
'alnp_google_analytics' => get_option( 'auto_load_next_post_google_analytics' ), |
|
514
|
|
|
'alnp_js_footer' => get_option( 'auto_load_next_post_load_js_in_footer' ), |
|
515
|
|
|
'alnp_disable_on_mobile' => get_option( 'auto_load_next_post_disable_on_mobile' ), |
|
516
|
|
|
'alnp_on_load_event' => get_option( 'auto_load_next_post_on_load_event' ), |
|
517
|
|
|
'alnp_on_entering_event' => get_option( 'auto_load_next_post_on_entering_event' ), |
|
518
|
|
|
); |
|
519
|
|
|
|
|
520
|
|
|
return $args; |
|
521
|
|
|
} // END alnp_get_settings() |
|
522
|
|
|
|
|
523
|
|
|
/** |
|
524
|
|
|
* Returns true or false if the page is ready for Auto Load Next Post |
|
525
|
|
|
* panel to show in the customizer. |
|
526
|
|
|
* |
|
527
|
|
|
* @access public |
|
528
|
|
|
* @since 1.5.0 |
|
529
|
|
|
* @return boolean |
|
530
|
|
|
*/ |
|
531
|
|
|
public function is_page_alnp_ready() { |
|
532
|
|
|
if ( is_front_page() && is_home() ) { |
|
533
|
|
|
return false; |
|
534
|
|
|
} elseif ( is_front_page() ) { |
|
535
|
|
|
return false; |
|
536
|
|
|
} elseif ( is_home() ) { |
|
537
|
|
|
return true; |
|
538
|
|
|
} elseif ( is_singular( apply_filters( 'alnp_customizer_posts_ready', array( 'post' ) ) ) ) { |
|
539
|
|
|
return true; |
|
540
|
|
|
} |
|
541
|
|
|
|
|
542
|
|
|
return true; |
|
543
|
|
|
} // END is_page_alnp_ready() |
|
544
|
|
|
|
|
545
|
|
|
/** |
|
546
|
|
|
* Sanitize the checkbox options. |
|
547
|
|
|
* |
|
548
|
|
|
* @access public |
|
549
|
|
|
* @since 1.6.0 |
|
550
|
|
|
* @param bool $input |
|
551
|
|
|
* @return string |
|
552
|
|
|
*/ |
|
553
|
|
|
public function sanitize_checkbox( $input ) { |
|
554
|
|
|
return ( $input === true ) ? 'yes' : 'no'; |
|
555
|
|
|
} // END sansitize_checkbox() |
|
556
|
|
|
|
|
557
|
|
|
} // END Class |
|
558
|
|
|
|
|
559
|
|
|
} // END if class |
|
560
|
|
|
|
|
561
|
|
|
new ALNP_Customizer(); |
|
562
|
|
|
|