PluginProbe
Passster – Password Protect Pages and Content / 4.3.17
Passster – Password Protect Pages and Content v4.3.17
4.3.17 4.3.16 4.3.15 4.3.14 4.3.12 4.3.13 4.3.11 4.3.10 4.3.9 4.3.8 4.3.7 4.3.6 4.3.5 trunk 3.5.4 3.5.5.2 3.5.5.8 3.5.5.9 4.0 4.1.4 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 All 49 releases
← All changes | inc/freemius/includes/fs-essential-functions.php +203 -192 4.0 → 4.3.17 View file →
@@ -9,8 +9,11 @@
9 9 * @copyright Copyright (c) 2015, Freemius, Inc.
10 10 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
11 11 * @since 1.1.5
12 12 */
13 + if ( ! defined( 'ABSPATH' ) ) {
14 + exit;
15 + }
13 16
14 17 if ( ! function_exists( 'fs_normalize_path' ) ) {
15 18 if ( function_exists( 'wp_normalize_path' ) ) {
16 19 /**
@@ -166,245 +169,253 @@
166 169 $_SERVER[ 'SERVER_ADDR' ];
167 170 }
168 171 }
169 172
170 - /**
171 - * Leverage backtrace to find caller plugin main file path.
172 - *
173 - * @author Vova Feldman (@svovaf)
174 - * @since 1.0.6
175 - *
176 - * @return string
177 - */
178 - function fs_find_caller_plugin_file() {
179 - /**
180 - * All the code below will be executed once on activation.
181 - * If the user changes the main plugin's file name, the file_exists()
182 - * will catch it.
183 - */
184 - if ( ! function_exists( 'get_plugins' ) ) {
185 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
186 - }
173 + if ( ! function_exists( 'fs_find_caller_plugin_file' ) ) {
174 + /**
175 + * Leverage backtrace to find caller plugin main file path.
176 + *
177 + * @author Vova Feldman (@svovaf)
178 + * @since 1.0.6
179 + *
180 + * @return string
181 + */
182 + function fs_find_caller_plugin_file() {
183 + /**
184 + * All the code below will be executed once on activation.
185 + * If the user changes the main plugin's file name, the file_exists()
186 + * will catch it.
187 + */
188 + if ( ! function_exists( 'get_plugins' ) ) {
189 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
190 + }
187 191
188 - $all_plugins = fs_get_plugins( true );
189 - $all_plugins_paths = array();
192 + $all_plugins = fs_get_plugins( true );
193 + $all_plugins_paths = array();
190 194
191 - // Get active plugin's main files real full names (might be symlinks).
192 - foreach ( $all_plugins as $relative_path => $data ) {
193 - $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
194 - }
195 + // Get active plugin's main files real full names (might be symlinks).
196 + foreach ( $all_plugins as $relative_path => $data ) {
197 + $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
198 + }
195 199
196 - $plugin_file = null;
197 - for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
198 - if ( empty( $bt[ $i ]['file'] ) ) {
199 - continue;
200 - }
200 + $plugin_file = null;
201 + for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
202 + if ( empty( $bt[ $i ]['file'] ) ) {
203 + continue;
204 + }
201 205
202 - if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) {
203 - $plugin_file = $bt[ $i ]['file'];
204 - break;
205 - }
206 - }
206 + if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) {
207 + $plugin_file = $bt[ $i ]['file'];
208 + break;
209 + }
210 + }
207 211
208 - if ( is_null( $plugin_file ) ) {
209 - // Throw an error to the developer in case of some edge case dev environment.
210 - wp_die(
211 - 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact [email protected] with the current error.',
212 - 'Error',
213 - array( 'back_link' => true )
214 - );
215 - }
212 + if ( is_null( $plugin_file ) ) {
213 + // Throw an error to the developer in case of some edge case dev environment.
214 + wp_die(
215 + 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact [email protected] with the current error.',
216 + 'Error',
217 + array( 'back_link' => true )
218 + );
219 + }
216 220
217 - return $plugin_file;
218 - }
221 + return $plugin_file;
222 + }
223 + }
219 224
220 225 require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-1.1.7.1.php';
221 226
222 - /**
223 - * Update SDK newest version reference.
224 - *
225 - * @author Vova Feldman (@svovaf)
226 - * @since 1.1.6
227 - *
228 - * @param string $sdk_relative_path
229 - * @param string|bool $plugin_file
230 - *
231 - * @global $fs_active_plugins
232 - */
233 - function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) {
234 - /**
235 - * If there is a plugin running an older version of FS (1.2.1 or below), the `fs_update_sdk_newest_version()`
236 - * function in the older version will be used instead of this one. But since the older version is using
237 - * the `is_plugin_active` function to check if a plugin is active, passing the theme's `plugin_path` to the
238 - * `is_plugin_active` function will return false since the path is not a plugin path, so `in_activation` will be
239 - * `true` for theme modules and the upgrading of the SDK version to 1.2.2 or newer version will work fine.
240 - *
241 - * Future versions that will call this function will use the proper logic here instead of just relying on the
242 - * `is_plugin_active` function to fail for themes.
243 - *
244 - * @author Leo Fajardo (@leorw)
245 - * @since 1.2.2
246 - */
227 + if ( ! function_exists( 'fs_update_sdk_newest_version' ) ) {
228 + /**
229 + * Update SDK newest version reference.
230 + *
231 + * @author Vova Feldman (@svovaf)
232 + * @since 1.1.6
233 + *
234 + * @param string $sdk_relative_path
235 + * @param string|bool $plugin_file
236 + *
237 + * @global $fs_active_plugins
238 + */
239 + function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) {
240 + /**
241 + * If there is a plugin running an older version of FS (1.2.1 or below), the `fs_update_sdk_newest_version()`
242 + * function in the older version will be used instead of this one. But since the older version is using
243 + * the `is_plugin_active` function to check if a plugin is active, passing the theme's `plugin_path` to the
244 + * `is_plugin_active` function will return false since the path is not a plugin path, so `in_activation` will be
245 + * `true` for theme modules and the upgrading of the SDK version to 1.2.2 or newer version will work fine.
246 + *
247 + * Future versions that will call this function will use the proper logic here instead of just relying on the
248 + * `is_plugin_active` function to fail for themes.
249 + *
250 + * @author Leo Fajardo (@leorw)
251 + * @since 1.2.2
252 + */
247 253
248 - global $fs_active_plugins;
254 + global $fs_active_plugins;
249 255
250 - $newest_sdk = $fs_active_plugins->plugins[ $sdk_relative_path ];
256 + $newest_sdk = $fs_active_plugins->plugins[ $sdk_relative_path ];
251 257
252 - if ( ! is_string( $plugin_file ) ) {
253 - $plugin_file = plugin_basename( fs_find_caller_plugin_file() );
254 - }
255 -
256 - if ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) {
257 - if ( ! function_exists( 'is_plugin_active' ) ) {
258 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
258 + if ( ! is_string( $plugin_file ) ) {
259 + $plugin_file = plugin_basename( fs_find_caller_plugin_file() );
259 260 }
260 261
261 - $in_activation = ( ! is_plugin_active( $plugin_file ) );
262 - } else {
263 - $theme = wp_get_theme();
264 - $in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet );
265 - }
262 + if ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) {
263 + if ( ! function_exists( 'is_plugin_active' ) ) {
264 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
265 + }
266 266
267 - $fs_active_plugins->newest = (object) array(
268 - 'plugin_path' => $plugin_file,
269 - 'sdk_path' => $sdk_relative_path,
270 - 'version' => $newest_sdk->version,
271 - 'in_activation' => $in_activation,
272 - 'timestamp' => time(),
273 - );
267 + $in_activation = ( ! is_plugin_active( $plugin_file ) );
268 + } else {
269 + $theme = wp_get_theme();
270 + $in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet );
271 + }
274 272
275 - // Update DB with latest SDK version and path.
276 - update_option( 'fs_active_plugins', $fs_active_plugins );
277 - }
273 + $fs_active_plugins->newest = (object) array(
274 + 'plugin_path' => $plugin_file,
275 + 'sdk_path' => $sdk_relative_path,
276 + 'version' => $newest_sdk->version,
277 + 'in_activation' => $in_activation,
278 + 'timestamp' => time(),
279 + );
278 280
279 - /**
280 - * Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first.
281 - *
282 - * @author Vova Feldman (@svovaf)
283 - * @since 1.1.6
284 - *
285 - * @return bool Was plugin order changed. Return false if plugin was loaded first anyways.
286 - *
287 - * @global $fs_active_plugins
288 - */
289 - function fs_newest_sdk_plugin_first() {
290 - global $fs_active_plugins;
281 + // Update DB with latest SDK version and path.
282 + update_option( 'fs_active_plugins', $fs_active_plugins );
283 + }
284 + }
291 285
286 + if ( ! function_exists( 'fs_newest_sdk_plugin_first' ) ) {
292 287 /**
293 - * @todo Multi-site network activated plugin are always loaded prior to site plugins so if there's a plugin activated in the network mode that has an older version of the SDK of another plugin which is site activated that has new SDK version, the fs-essential-functions.php will be loaded from the older SDK. Same thing about MU plugins (loaded even before network activated plugins).
288 + * Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first.
294 289 *
295 - * @link https://github.com/Freemius/wordpress-sdk/issues/26
290 + * @author Vova Feldman (@svovaf)
291 + * @since 1.1.6
292 + *
293 + * @return bool Was plugin order changed. Return false if plugin was loaded first anyways.
294 + *
295 + * @global $fs_active_plugins
296 296 */
297 + function fs_newest_sdk_plugin_first() {
298 + global $fs_active_plugins;
297 299
298 - $newest_sdk_plugin_path = $fs_active_plugins->newest->plugin_path;
300 + /**
301 + * @todo Multi-site network activated plugin are always loaded prior to site plugins so if there's a plugin activated in the network mode that has an older version of the SDK of another plugin which is site activated that has new SDK version, the fs-essential-functions.php will be loaded from the older SDK. Same thing about MU plugins (loaded even before network activated plugins).
302 + *
303 + * @link https://github.com/Freemius/wordpress-sdk/issues/26
304 + */
299 305
300 - $active_plugins = get_option( 'active_plugins', array() );
301 - $updated_active_plugins = array( $newest_sdk_plugin_path );
306 + $newest_sdk_plugin_path = $fs_active_plugins->newest->plugin_path;
302 307
303 - $plugin_found = false;
304 - $is_first_path = true;
308 + $active_plugins = get_option( 'active_plugins', array() );
309 + $updated_active_plugins = array( $newest_sdk_plugin_path );
305 310
306 - foreach ( $active_plugins as $key => $plugin_path ) {
307 - if ( $plugin_path === $newest_sdk_plugin_path ) {
308 - if ( $is_first_path ) {
309 - // if it's the first plugin already, no need to continue
310 - return false;
311 + $plugin_found = false;
312 + $is_first_path = true;
313 +
314 + foreach ( $active_plugins as $key => $plugin_path ) {
315 + if ( $plugin_path === $newest_sdk_plugin_path ) {
316 + if ( $is_first_path ) {
317 + // if it's the first plugin already, no need to continue
318 + return false;
319 + }
320 +
321 + $plugin_found = true;
322 +
323 + // Skip the plugin (it is already added as the 1st item of $updated_active_plugins).
324 + continue;
311 325 }
312 326
313 - $plugin_found = true;
327 + $updated_active_plugins[] = $plugin_path;
314 328
315 - // Skip the plugin (it is already added as the 1st item of $updated_active_plugins).
316 - continue;
329 + if ( $is_first_path ) {
330 + $is_first_path = false;
331 + }
317 332 }
318 333
319 - $updated_active_plugins[] = $plugin_path;
334 + if ( $plugin_found ) {
335 + update_option( 'active_plugins', $updated_active_plugins );
320 336
321 - if ( $is_first_path ) {
322 - $is_first_path = false;
337 + return true;
323 338 }
324 - }
325 339
326 - if ( $plugin_found ) {
327 - update_option( 'active_plugins', $updated_active_plugins );
340 + if ( is_multisite() ) {
341 + // Plugin is network active.
342 + $network_active_plugins = get_site_option( 'active_sitewide_plugins', array() );
328 343
329 - return true;
330 - }
344 + if ( isset( $network_active_plugins[ $newest_sdk_plugin_path ] ) ) {
345 + reset( $network_active_plugins );
346 + if ( $newest_sdk_plugin_path === key( $network_active_plugins ) ) {
347 + // Plugin is already activated first on the network level.
348 + return false;
349 + } else {
350 + $time = $network_active_plugins[ $newest_sdk_plugin_path ];
331 351
332 - if ( is_multisite() ) {
333 - // Plugin is network active.
334 - $network_active_plugins = get_site_option( 'active_sitewide_plugins', array() );
352 + // Remove plugin from its current position.
353 + unset( $network_active_plugins[ $newest_sdk_plugin_path ] );
335 354
336 - if ( isset( $network_active_plugins[ $newest_sdk_plugin_path ] ) ) {
337 - reset( $network_active_plugins );
338 - if ( $newest_sdk_plugin_path === key( $network_active_plugins ) ) {
339 - // Plugin is already activated first on the network level.
340 - return false;
341 - } else {
342 - $time = $network_active_plugins[ $newest_sdk_plugin_path ];
355 + // Set it to be included first.
356 + $network_active_plugins = array( $newest_sdk_plugin_path => $time ) + $network_active_plugins;
343 357
344 - // Remove plugin from its current position.
345 - unset( $network_active_plugins[ $newest_sdk_plugin_path ] );
358 + update_site_option( 'active_sitewide_plugins', $network_active_plugins );
346 359
347 - // Set it to be included first.
348 - $network_active_plugins = array( $newest_sdk_plugin_path => $time ) + $network_active_plugins;
349 -
350 - update_site_option( 'active_sitewide_plugins', $network_active_plugins );
351 -
352 - return true;
360 + return true;
361 + }
353 362 }
354 363 }
364 +
365 + return false;
355 366 }
356 -
357 - return false;
358 367 }
359 368
360 - /**
361 - * Go over all Freemius SDKs in the system and find and "remember"
362 - * the newest SDK which is associated with an active plugin.
363 - *
364 - * @author Vova Feldman (@svovaf)
365 - * @since 1.1.6
366 - *
367 - * @global $fs_active_plugins
368 - */
369 - function fs_fallback_to_newest_active_sdk() {
370 - global $fs_active_plugins;
369 + if ( ! function_exists( 'fs_fallback_to_newest_active_sdk' ) ) {
370 + /**
371 + * Go over all Freemius SDKs in the system and find and "remember"
372 + * the newest SDK which is associated with an active plugin.
373 + *
374 + * @author Vova Feldman (@svovaf)
375 + * @since 1.1.6
376 + *
377 + * @global $fs_active_plugins
378 + */
379 + function fs_fallback_to_newest_active_sdk() {
380 + global $fs_active_plugins;
371 381
372 - /**
373 - * @var object $newest_sdk_data
374 - */
375 - $newest_sdk_data = null;
376 - $newest_sdk_path = null;
382 + /**
383 + * @var object $newest_sdk_data
384 + */
385 + $newest_sdk_data = null;
386 + $newest_sdk_path = null;
377 387
378 - foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) {
379 - if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' )
380 - ) {
381 - // If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
382 - if ( 'plugin' === $data->type ) {
383 - $is_module_active = is_plugin_active( $data->plugin_path );
384 - } else {
385 - $active_theme = wp_get_theme();
386 - $is_module_active = ( $data->plugin_path === $active_theme->get_template() );
387 - }
388 + foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) {
389 + if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' )
390 + ) {
391 + // If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
392 + if ( 'plugin' === $data->type ) {
393 + $is_module_active = is_plugin_active( $data->plugin_path );
394 + } else {
395 + $active_theme = wp_get_theme();
396 + $is_module_active = ( $data->plugin_path === $active_theme->get_template() );
397 + }
388 398
389 - $is_sdk_exists = file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) );
399 + $is_sdk_exists = file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) );
390 400
391 - if ( ! $is_module_active || ! $is_sdk_exists ) {
392 - unset( $fs_active_plugins->plugins[ $sdk_relative_path ] );
401 + if ( ! $is_module_active || ! $is_sdk_exists ) {
402 + unset( $fs_active_plugins->plugins[ $sdk_relative_path ] );
393 403
394 - // No need to store the data since it will be stored in fs_update_sdk_newest_version()
395 - // or explicitly with update_option().
396 - } else {
397 - $newest_sdk_data = $data;
398 - $newest_sdk_path = $sdk_relative_path;
399 - }
400 - }
401 - }
404 + // No need to store the data since it will be stored in fs_update_sdk_newest_version()
405 + // or explicitly with update_option().
406 + } else {
407 + $newest_sdk_data = $data;
408 + $newest_sdk_path = $sdk_relative_path;
409 + }
410 + }
411 + }
402 412
403 - if ( is_null( $newest_sdk_data ) ) {
404 - // Couldn't find any SDK reference.
405 - $fs_active_plugins = new stdClass();
406 - update_option( 'fs_active_plugins', $fs_active_plugins );
407 - } else {
408 - fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
409 - }
410 - }
413 + if ( is_null( $newest_sdk_data ) ) {
414 + // Couldn't find any SDK reference.
415 + $fs_active_plugins = new stdClass();
416 + update_option( 'fs_active_plugins', $fs_active_plugins );
417 + } else {
418 + fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
419 + }
420 + }
421 + }