1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Auto Load Next Post Conditional Functions |
4
|
|
|
* |
5
|
|
|
* Functions for determining the current query/page, |
6
|
|
|
* theme support and if user agent is a bot. |
7
|
|
|
* |
8
|
|
|
* @since 1.0.0 |
9
|
|
|
* @version 1.6.0 |
10
|
|
|
* @author Sébastien Dumont |
11
|
|
|
* @category Core |
12
|
|
|
* @package Auto Load Next Post/Functions |
13
|
|
|
* @license GPL-2.0+ |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
// Exit if accessed directly. |
17
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
18
|
|
|
exit; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
if ( ! function_exists( 'alnp_template_location' ) ) { |
22
|
|
|
/** |
23
|
|
|
* Filters the template location for get_template_part(). |
24
|
|
|
* |
25
|
|
|
* @since 1.4.8 |
26
|
|
|
* @version 1.5.0 |
27
|
|
|
* @return boolean |
28
|
|
|
*/ |
29
|
|
|
function alnp_template_location() { |
30
|
|
|
$current_theme = get_option('template'); |
31
|
|
|
|
32
|
|
|
switch( $current_theme ) { |
33
|
|
|
case 'twentyseventeen': |
34
|
|
|
$path = 'template-parts/post/'; |
35
|
|
|
break; |
36
|
|
|
|
37
|
|
|
case 'twentysixteen': |
38
|
|
|
$path = 'template-parts/'; |
39
|
|
|
break; |
40
|
|
|
|
41
|
|
|
default: |
42
|
|
|
$path = ''; |
43
|
|
|
break; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return apply_filters( 'alnp_template_location', $path ); |
47
|
|
|
} // END alnp_template_location() |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if ( ! function_exists( 'is_alnp_pro_version_installed' ) ) { |
51
|
|
|
/** |
52
|
|
|
* Detects if Auto Load Next Post Pro is installed. |
53
|
|
|
* |
54
|
|
|
* @since 1.4.10 |
55
|
|
|
* @return boolean |
56
|
|
|
*/ |
57
|
|
|
function is_alnp_pro_version_installed() { |
58
|
|
|
$active_plugins = (array) get_option( 'active_plugins', array() ); |
59
|
|
|
|
60
|
|
|
if ( is_multisite() ) { |
61
|
|
|
$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return in_array( 'auto-load-next-post-pro/auto-load-next-post-pro.php', $active_plugins ) || array_key_exists( 'auto-load-next-post-pro/auto-load-next-post-pro.php', $active_plugins ); |
65
|
|
|
} // END is_alnp_pro_version_installed() |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if ( ! function_exists( 'is_alnp_beta' ) ) { |
69
|
|
|
/** |
70
|
|
|
* Returns true if Auto Load Next Post is a beta/pre-release. |
71
|
|
|
* |
72
|
|
|
* @since 1.5.0 |
73
|
|
|
* @version 1.6.0 |
74
|
|
|
* @return boolean |
75
|
|
|
*/ |
76
|
|
|
function is_alnp_beta() { |
77
|
|
|
if ( |
78
|
|
|
strpos( AUTO_LOAD_NEXT_POST_VERSION, 'beta' ) || |
79
|
|
|
strpos( AUTO_LOAD_NEXT_POST_VERSION, 'rc' ) |
80
|
|
|
) { |
81
|
|
|
return true; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return false; |
85
|
|
|
} // END is_alnp_beta() |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ( ! function_exists( 'is_alnp_active_theme' ) ) { |
89
|
|
|
/** |
90
|
|
|
* See if theme/s is activate or not. |
91
|
|
|
* |
92
|
|
|
* @since 1.5.0 |
93
|
|
|
* @param string|array $theme Theme name or array of theme names to check. |
94
|
|
|
* @return boolean |
95
|
|
|
*/ |
96
|
|
|
function is_alnp_active_theme( $theme ) { |
97
|
|
|
return is_array( $theme ) ? in_array( get_template(), $theme, true ) : get_template() === $theme; |
98
|
|
|
} // END is_alnp_active_theme() |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if ( ! function_exists( 'is_alnp_supported' ) ) { |
102
|
|
|
/** |
103
|
|
|
* Returns true if Auto Load Next Post is supported in the theme. |
104
|
|
|
* |
105
|
|
|
* @since 1.5.0 |
106
|
|
|
* @return boolean |
107
|
|
|
*/ |
108
|
|
|
function is_alnp_supported() { |
109
|
|
|
$theme_support = current_theme_supports( 'auto-load-next-post' ); |
110
|
|
|
|
111
|
|
|
if ( ! $theme_support ) { |
112
|
|
|
return false; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return true; |
116
|
|
|
} // END is_alnp_supported() |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
if ( ! function_exists( 'alnp_get_theme_support' ) ) { |
120
|
|
|
/** |
121
|
|
|
* Return "theme support" values from the current theme, if set. |
122
|
|
|
* |
123
|
|
|
* @since 1.5.0 |
124
|
|
|
* @param string $prop Name of prop (or key::subkey for arrays of props) if you want a specific value. Leave blank to get all props as an array. |
125
|
|
|
* @param mixed $default Optional value to return if the theme does not declare support for a prop. |
126
|
|
|
* @return mixed Value of prop(s). |
127
|
|
|
*/ |
128
|
|
|
function alnp_get_theme_support( $prop = '', $default = null ) { |
129
|
|
|
$theme_support = get_theme_support( 'auto-load-next-post' ); |
130
|
|
|
$theme_support = is_array( $theme_support ) ? $theme_support[0] : false; |
131
|
|
|
|
132
|
|
|
if ( ! $theme_support ) { |
133
|
|
|
return $default; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
if ( ! empty( $prop ) ) { |
137
|
|
|
$prop_stack = explode( '::', $prop ); |
138
|
|
|
$prop_key = array_shift( $prop_stack ); |
139
|
|
|
|
140
|
|
|
if ( isset( $theme_support[ $prop_key ] ) ) { |
141
|
|
|
$value = $theme_support[ $prop_key ]; |
142
|
|
|
|
143
|
|
|
if ( count( $prop_stack ) ) { |
144
|
|
|
foreach ( $prop_stack as $prop_key ) { |
145
|
|
|
if ( is_array( $value ) && isset( $value[ $prop_key ] ) ) { |
146
|
|
|
$value = $value[ $prop_key ]; |
147
|
|
|
} else { |
148
|
|
|
$value = $default; |
149
|
|
|
break; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
} else { |
154
|
|
|
$value = $default; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
return $value; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
return $theme_support; |
161
|
|
|
} // END alnp_get_theme_support() |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
if ( ! function_exists( 'alnp_is_bot' ) ) { |
165
|
|
|
/** |
166
|
|
|
* Was the current request made by a known bot? |
167
|
|
|
* |
168
|
|
|
* @since 1.5.0 |
169
|
|
|
* @return boolean |
170
|
|
|
*/ |
171
|
|
|
function alnp_is_bot() { |
172
|
|
|
$is_bot = alnp_is_bot_user_agent( $_SERVER['HTTP_USER_AGENT'] ); |
173
|
|
|
|
174
|
|
|
return $is_bot; |
175
|
|
|
} // END alnp_is_bot() |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
if ( ! function_exists( 'alnp_is_bot_user_agent' ) ) { |
179
|
|
|
/** |
180
|
|
|
* Is the given user-agent a known bot? |
181
|
|
|
* |
182
|
|
|
* @since 1.5.0 |
183
|
|
|
* @param string A user-agent string |
184
|
|
|
* @return boolean |
185
|
|
|
*/ |
186
|
|
|
function alnp_is_bot_user_agent( $ua = null ) { |
187
|
|
|
if ( empty( $ua ) ) { |
188
|
|
|
return false; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
$bot_agents = array( |
192
|
|
|
'alexa', 'altavista', 'ask jeeves', 'attentio', 'baiduspider', 'bingbot', 'chtml generic', 'crawler', 'fastmobilecrawl', |
193
|
|
|
'feedfetcher-google', 'firefly', 'froogle', 'gigabot', 'googlebot', 'googlebot-mobile', 'heritrix', 'httrack', 'ia_archiver', 'irlbot', |
194
|
|
|
'iescholar', 'infoseek', 'jumpbot', 'linkcheck', 'lycos', 'mediapartners', 'mediobot', 'motionbot', 'msnbot', 'mshots', 'openbot', |
195
|
|
|
'pss-webkit-request', 'pythumbnail', 'scooter', 'slurp', 'snapbot', 'spider', 'taptubot', 'technoratisnoop', |
196
|
|
|
'teoma', 'twiceler', 'yahooseeker', 'yahooysmcm', 'yammybot', 'ahrefsbot', 'pingdom.com_bot', 'kraken', 'yandexbot', |
197
|
|
|
'twitterbot', 'tweetmemebot', 'openhosebot', 'queryseekerspider', 'linkdexbot', 'grokkit-crawler', |
198
|
|
|
'livelapbot', 'germcrawler', 'domaintunocrawler', 'grapeshotcrawler', 'cloudflare-alwaysonline', |
199
|
|
|
); |
200
|
|
|
|
201
|
|
|
foreach ( $bot_agents as $bot_agent ) { |
202
|
|
|
if ( false !== stripos( $ua, $bot_agent ) ) { |
203
|
|
|
return true; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
return false; |
208
|
|
|
} // END alnp_is_bot_user_agent() |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
if ( ! function_exists( 'alnp_check_jetpack' ) ) { |
212
|
|
|
/** |
213
|
|
|
* Check if Jetpack is installed. |
214
|
|
|
* |
215
|
|
|
* @since 1.5.0 |
216
|
|
|
* @return string |
217
|
|
|
*/ |
218
|
|
|
function alnp_check_jetpack() { |
219
|
|
|
$jetpack_active = class_exists( 'Jetpack' ); |
220
|
|
|
|
221
|
|
|
$is_active = $jetpack_active ? 'yes' : 'no'; |
222
|
|
|
|
223
|
|
|
return $is_active; |
224
|
|
|
} // END alnp_check_jetpack() |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
if ( ! function_exists( 'alnp_airplane_mode_enabled' ) ) { |
228
|
|
|
/** |
229
|
|
|
* Check the current status of Airplane Mode. |
230
|
|
|
* |
231
|
|
|
* @since 1.6.0 |
232
|
|
|
* @return bool True if status is 'on'; false if not. |
233
|
|
|
*/ |
234
|
|
|
function alnp_airplane_mode_enabled() { |
235
|
|
|
// Bail if CLI. |
236
|
|
|
if ( defined( 'WP_CLI' ) and WP_CLI ) { |
237
|
|
|
return false; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
// Pull our status from the options table. |
241
|
|
|
$option = get_site_option( 'airplane-mode' ); |
242
|
|
|
|
243
|
|
|
// Backup check for regular options table. |
244
|
|
|
if ( false === $option ) { |
245
|
|
|
$option = get_option( 'airplane-mode' ); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
// Return the option flag. |
249
|
|
|
return 'on' === $option; |
250
|
|
|
} // END alnp_airplane_mode_enabled() |
251
|
|
|
} |