1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Plugin Name: Auto Load Next Post |
4
|
|
|
* Plugin URI: https://autoloadnextpost.com |
5
|
|
|
* Description: Increase your pageviews on your site as readers continue reading your posts scrolling down the page. |
6
|
|
|
* Author: Sébastien Dumont |
7
|
|
|
* Author URI: https://sebastiendumont.com |
8
|
|
|
* Version: 1.6.0-beta.1 |
9
|
|
|
* Text Domain: auto-load-next-post |
10
|
|
|
* Domain Path: /languages/ |
11
|
|
|
* |
12
|
|
|
* Copyright: © 2019 Sébastien Dumont, ([email protected]) |
13
|
|
|
* |
14
|
|
|
* License: GNU General Public License v3.0 |
15
|
|
|
* License URI: http://www.gnu.org/licenses/gpl-3.0.html |
16
|
|
|
* |
17
|
|
|
* @package Auto Load Next Post |
18
|
|
|
* @author Sébastien Dumont |
19
|
|
|
* @copyright Copyright © 2019, Sébastien Dumont |
20
|
|
|
* @license GNU General Public License v3.0 http://www.gnu.org/licenses/gpl-3.0.html |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Main Auto Load Next Post Class |
25
|
|
|
* |
26
|
|
|
* The main instance of the plugin. |
27
|
|
|
*/ |
28
|
|
|
if ( ! class_exists( 'Auto_Load_Next_Post' ) ) { |
29
|
|
|
|
30
|
|
|
class Auto_Load_Next_Post { |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var Auto_Load_Next_Post - The single instance of the class |
34
|
|
|
* |
35
|
|
|
* @access protected |
36
|
|
|
* @static |
37
|
|
|
* @since 1.0.0 |
38
|
|
|
*/ |
39
|
|
|
protected static $_instance = null; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Plugin Version |
43
|
|
|
* |
44
|
|
|
* @access public |
45
|
|
|
* @static |
46
|
|
|
* @since 1.5.0 |
47
|
|
|
*/ |
48
|
|
|
public static $version = '1.6.0-beta.1'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Main Auto Load Next Post Instance |
52
|
|
|
* |
53
|
|
|
* Ensures only one instance of Auto Load Next Post is loaded or can be loaded. |
54
|
|
|
* |
55
|
|
|
* @access public |
56
|
|
|
* @since 1.0.0 |
57
|
|
|
* @static |
58
|
|
|
* @see Auto_Load_Next_Post() |
59
|
|
|
* @return Auto_Load_Next_Post Single instance. |
60
|
|
|
*/ |
61
|
|
|
public static function instance() { |
62
|
|
|
if ( is_null( self::$_instance ) ) { |
63
|
|
|
self::$_instance = new self(); |
64
|
|
|
} |
65
|
|
|
return self::$_instance; |
66
|
|
|
} // END instance() |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Cloning is forbidden. |
70
|
|
|
* |
71
|
|
|
* @access public |
72
|
|
|
* @since 1.0.0 |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
|
|
public function __clone() { |
76
|
|
|
// Cloning instances of the class is forbidden |
77
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Cloning this object is forbidden.', 'auto-load-next-post' ), self::$version ); |
78
|
|
|
} // END __clone() |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Unserializing instances of this class is forbidden. |
82
|
|
|
* |
83
|
|
|
* @access public |
84
|
|
|
* @since 1.0.0 |
85
|
|
|
* @return void |
86
|
|
|
*/ |
87
|
|
|
public function __wakeup() { |
88
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'auto-load-next-post' ), self::$version ); |
89
|
|
|
} // END __wakeup() |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Auto_Load_Next_Post Constructor |
93
|
|
|
* |
94
|
|
|
* @access public |
95
|
|
|
* @since 1.0.0 |
96
|
|
|
* @version 1.5.0 |
97
|
|
|
*/ |
98
|
|
|
public function __construct() { |
99
|
|
|
$this->setup_constants(); |
100
|
|
|
$this->includes(); |
101
|
|
|
$this->init_hooks(); |
102
|
|
|
|
103
|
|
|
// Auto Load Next Post is fully loaded. |
104
|
|
|
do_action( 'auto_load_next_post_loaded' ); |
105
|
|
|
} // END __construct() |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Hooks into action hooks. |
109
|
|
|
* |
110
|
|
|
* @access public |
111
|
|
|
* @since 1.5.0 |
112
|
|
|
*/ |
113
|
|
|
public function init_hooks() { |
114
|
|
|
// Load translation files. |
115
|
|
|
add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); |
116
|
|
|
|
117
|
|
|
// Load Auto Load Next Post scripts on the frontend. |
118
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'alnp_enqueue_scripts' ) ); |
119
|
|
|
} // END init_hooks() |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Setup Constants |
123
|
|
|
* |
124
|
|
|
* @access private |
125
|
|
|
* @since 1.4.3 |
126
|
|
|
* @version 1.5.12 |
127
|
|
|
*/ |
128
|
|
|
private function setup_constants() { |
129
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_VERSION', self::$version); |
130
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_FILE', __FILE__); |
131
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_SLUG', 'auto-load-next-post'); |
132
|
|
|
|
133
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_URL_PATH', untrailingslashit( plugins_url( '/', __FILE__ ) ) ); |
134
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_FILE_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
135
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_TEMPLATE_PATH', 'auto-load-next-post/'); |
136
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_3RD_PARTY', AUTO_LOAD_NEXT_POST_FILE_PATH . '/includes/3rd-party/'); |
137
|
|
|
|
138
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_WP_VERSION_REQUIRE', '4.4'); |
139
|
|
|
|
140
|
|
|
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
141
|
|
|
$debug_suffix = defined('ALNP_DEV_DEBUG') && ALNP_DEV_DEBUG ? '.dev' : ''; |
142
|
|
|
|
143
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_SCRIPT_MODE', $suffix); |
144
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_DEBUG_MODE', $debug_suffix); |
145
|
|
|
|
146
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_STORE_URL', 'https://autoloadnextpost.com/'); |
147
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_PLUGIN_URL', 'https://wordpress.org/plugins/auto-load-next-post/'); |
148
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_SUPPORT_URL', 'https://wordpress.org/support/plugin/auto-load-next-post'); |
149
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_REVIEW_URL', 'https://wordpress.org/support/plugin/auto-load-next-post/reviews/'); |
150
|
|
|
$this->define('AUTO_LOAD_NEXT_POST_DOCUMENTATION_URL', 'https://github.com/autoloadnextpost/alnp-documentation/tree/master/en_US#the-manual'); |
151
|
|
|
} // END setup_constants() |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Define constant if not already set. |
155
|
|
|
* |
156
|
|
|
* @access private |
157
|
|
|
* @since 1.4.3 |
158
|
|
|
* @param string $name |
159
|
|
|
* @param string|bool $value |
160
|
|
|
*/ |
161
|
|
|
private function define( $name, $value ) { |
162
|
|
|
if ( ! defined( $name ) ) { |
163
|
|
|
define( $name, $value ); |
164
|
|
|
} |
165
|
|
|
} // END define() |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Include required core files used in admin and on the frontend. |
169
|
|
|
* |
170
|
|
|
* @access public |
171
|
|
|
* @since 1.0.0 |
172
|
|
|
* @version 1.6.0 |
173
|
|
|
* @return void |
174
|
|
|
*/ |
175
|
|
|
public function includes() { |
176
|
|
|
include_once( dirname( __FILE__ ) . '/includes/class-alnp-autoloader.php' ); // Autoloader. |
177
|
|
|
include_once( dirname( __FILE__ ) . '/includes/auto-load-next-post-deprecated-functions.php' ); // Deprecated functions. |
178
|
|
|
include_once( dirname( __FILE__ ) . '/includes/auto-load-next-post-conditional-functions.php' ); // Conditional functions. |
179
|
|
|
include_once( dirname( __FILE__ ) . '/includes/auto-load-next-post-formatting-functions.php' ); // Formatting functions. |
180
|
|
|
include_once( dirname( __FILE__ ) . '/includes/auto-load-next-post-themes-supported.php' ); // Handles all supported themes out of the box. |
181
|
|
|
include_once( dirname( __FILE__ ) . '/includes/auto-load-next-post-core-functions.php' ); // Contains core functions for the front/back end. |
182
|
|
|
include_once( dirname( __FILE__ ) . '/includes/auto-load-next-post-template-functions.php' ); // Template Functions |
183
|
|
|
include_once( dirname( __FILE__ ) . '/includes/auto-load-next-post-template-hooks.php' ); // Template Hooks |
184
|
|
|
|
185
|
|
|
// Include theme support. |
186
|
|
|
alnp_include_theme_support(); |
187
|
|
|
|
188
|
|
|
// 3rd Party support. |
189
|
|
|
include_once( dirname( __FILE__ ) . '/includes/3rd-party/3rd-party.php' ); |
190
|
|
|
|
191
|
|
|
// Customizer. |
192
|
|
|
include_once( dirname( __FILE__ ) . '/includes/customizer/class-alnp-customizer.php' ); |
193
|
|
|
include_once( dirname( __FILE__ ) . '/includes/customizer/class-alnp-customizer-scripts.php' ); |
194
|
|
|
|
195
|
|
|
// Ajax |
196
|
|
|
include_once( dirname( __FILE__ ) . '/includes/class-alnp-ajax.php' ); |
197
|
|
|
|
198
|
|
|
// Include admin class to handle all back-end functions. |
199
|
|
|
if ( is_admin() ) { |
200
|
|
|
include_once( dirname( __FILE__ ) . '/includes/admin/class-alnp-admin.php' ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
// Install. |
204
|
|
|
require_once( dirname( __FILE__ ) . '/includes/class-alnp-install.php' ); |
205
|
|
|
} // END includes() |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Make the plugin translation ready. |
209
|
|
|
* |
210
|
|
|
* Translations should be added in the WordPress language directory: |
211
|
|
|
* - WP_LANG_DIR/plugins/auto-load-next-post-LOCALE.mo |
212
|
|
|
* |
213
|
|
|
* @access public |
214
|
|
|
* @since 1.0.0 |
215
|
|
|
* @version 1.4.10 |
216
|
|
|
* @return void |
217
|
|
|
*/ |
218
|
|
|
public function load_plugin_textdomain() { |
219
|
|
|
load_plugin_textdomain( 'auto-load-next-post', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
220
|
|
|
} // END load_plugin_textdomain() |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Registers and enqueues stylesheets and javascripts for the front of the site. |
224
|
|
|
* |
225
|
|
|
* @access public |
226
|
|
|
* @since 1.3.2 |
227
|
|
|
* @version 1.6.0 |
228
|
|
|
*/ |
229
|
|
|
public function alnp_enqueue_scripts() { |
230
|
|
|
// Prevent enqueue scripts if feed, trackback or a preview of a post. |
231
|
|
|
if ( is_feed() || is_trackback() || is_preview() ) { |
232
|
|
|
return; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
// Load the Javascript if found as a singluar post and the user is not a bot. |
236
|
|
|
if ( ! alnp_is_bot() && is_singular() && get_post_type() == 'post' ) { |
237
|
|
|
// This checks to see if the JavaScript should load in the footer or not. |
238
|
|
|
$load_in_footer = alnp_load_js_in_footer(); |
239
|
|
|
|
240
|
|
|
// This checks to see if we should disable Auto Load Next Post from running on mobile devices. |
241
|
|
|
$disable_mobile = alnp_disable_on_mobile(); |
242
|
|
|
|
243
|
|
|
$this->load_file( 'auto-load-next-post-scrollspy', '/assets/js/libs/scrollspy.min.js', true, array('jquery'), AUTO_LOAD_NEXT_POST_VERSION, $load_in_footer ); |
244
|
|
|
|
245
|
|
|
// Only load History.js when not in the customizer. |
246
|
|
|
if ( ! is_customize_preview() ) { |
247
|
|
|
$this->load_file( 'auto-load-next-post-history', '/assets/js/libs/jquery.history.js', true, array('jquery'), AUTO_LOAD_NEXT_POST_VERSION, $load_in_footer ); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
$this->load_file( 'auto-load-next-post-script', '/assets/js/frontend/auto-load-next-post' . AUTO_LOAD_NEXT_POST_DEBUG_MODE.AUTO_LOAD_NEXT_POST_SCRIPT_MODE . '.js', true, array('auto-load-next-post-scrollspy'), AUTO_LOAD_NEXT_POST_VERSION, $load_in_footer ); |
251
|
|
|
|
252
|
|
|
// Variables for the JavaScript |
253
|
|
|
wp_localize_script( 'auto-load-next-post-script', 'auto_load_next_post_params', array( |
254
|
|
|
'alnp_version' => AUTO_LOAD_NEXT_POST_VERSION, |
255
|
|
|
'alnp_content_container' => get_option( 'auto_load_next_post_content_container' ), |
256
|
|
|
'alnp_title_selector' => get_option( 'auto_load_next_post_title_selector' ), |
257
|
|
|
'alnp_navigation_container' => get_option( 'auto_load_next_post_navigation_container' ), |
258
|
|
|
'alnp_comments_container' => get_option( 'auto_load_next_post_comments_container' ), |
259
|
|
|
'alnp_remove_comments' => get_option( 'auto_load_next_post_remove_comments' ), |
260
|
|
|
'alnp_google_analytics' => get_option( 'auto_load_next_post_google_analytics' ), |
261
|
|
|
'alnp_event_on_load' => get_option( 'auto_load_next_post_on_load_event' ), |
262
|
|
|
'alnp_event_on_entering' => get_option( 'auto_load_next_post_on_entering_event' ), |
263
|
|
|
'alnp_is_customizer' => $this->is_alnp_using_customizer(), |
264
|
|
|
'alnp_load_in_footer' => $load_in_footer, |
265
|
|
|
'alnp_is_mobile' => $this->is_mobile(), |
266
|
|
|
'alnp_disable_mobile' => $disable_mobile |
267
|
|
|
) ); |
268
|
|
|
} // END if is_singular() && get_post_type() |
269
|
|
|
} // END alnp_enqueue_scripts() |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Checks if we are using the theme customizer. |
273
|
|
|
* |
274
|
|
|
* @access public |
275
|
|
|
* @since 1.5.0 |
276
|
|
|
* @static |
277
|
|
|
* @return string|bool |
278
|
|
|
*/ |
279
|
|
|
public static function is_alnp_using_customizer() { |
280
|
|
|
if ( is_customize_preview() ) { |
281
|
|
|
return "yes"; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
return false; |
285
|
|
|
} // END is_alnp_using_customizer() |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Check if the site is viewed on a mobile device. |
289
|
|
|
* |
290
|
|
|
* @access public |
291
|
|
|
* @since 1.6.0 |
292
|
|
|
* @static |
293
|
|
|
* @return string|bool |
294
|
|
|
*/ |
295
|
|
|
public static function is_mobile() { |
296
|
|
|
if ( wp_is_mobile() ) { |
297
|
|
|
return "yes"; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
return false; |
301
|
|
|
} // END is_mobile() |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* Helper function for registering and enqueueing scripts and styles. |
305
|
|
|
* |
306
|
|
|
* @access public |
307
|
|
|
* @since 1.0.0 |
308
|
|
|
* @version 1.5.0 |
309
|
|
|
* @static |
310
|
|
|
* @param string $name The ID to register with WordPress. |
311
|
|
|
* @param string $file_path The path to the actual file. |
312
|
|
|
* @param bool $is_script Optional, argument for if the incoming file_path is a JavaScript source file. |
313
|
|
|
* @param array $support Optional, for requiring other javascripts for the source file you are calling. |
314
|
|
|
* @param string $version Optional, can match the version of the plugin or version of the source file. |
315
|
|
|
* @param bool $footer Optional, can set the JavaScript to load in the footer instead. |
316
|
|
|
*/ |
317
|
|
|
public static function load_file( $name, $file_path, $is_script = false, $support = array(), $version = '', $footer = false ) { |
318
|
|
|
$url = AUTO_LOAD_NEXT_POST_URL_PATH . $file_path; // URL to the file. |
319
|
|
|
|
320
|
|
|
if ( file_exists( AUTO_LOAD_NEXT_POST_FILE_PATH . $file_path ) ) { |
321
|
|
|
if ( $is_script ) { |
322
|
|
|
if ( !wp_script_is( $name, 'registered' ) ) { |
323
|
|
|
wp_register_script( $name, $url, $support, $version, $footer ); |
324
|
|
|
wp_enqueue_script( $name ); |
325
|
|
|
} |
326
|
|
|
} else { |
327
|
|
|
if ( !wp_style_is( $name, 'registered' ) ) { |
328
|
|
|
wp_register_style( $name, $url ); |
329
|
|
|
wp_enqueue_style( $name ); |
330
|
|
|
} |
331
|
|
|
} // end if |
332
|
|
|
} // end if |
333
|
|
|
|
334
|
|
|
} // END load_file() |
335
|
|
|
|
336
|
|
|
} // END Auto_Load_Next_Post() |
337
|
|
|
|
338
|
|
|
} // END class exists 'Auto_Load_Next_Post' |
339
|
|
|
|
340
|
|
|
return Auto_Load_Next_Post::instance(); |
341
|
|
|
|