PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 2.3.8
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v2.3.8
2.9.1 2.9.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 2.0.0 2.1.0 2.2.0 2.3.2 2.3.3 2.3.5 2.3.6 2.3.8 2.3.9 2.4.3 All 37 releases
← All changes | freemius/includes/fs-essential-functions.php +207 -289 1.6.12.3.8 View file →
@@ -148,90 +148,14 @@
148 148 }
149 149
150 150 #endregion Core Redirect (copied from BuddyPress) -----------------------------------------
151 151
152 - if ( ! function_exists( '__fs' ) ) {
153 - global $fs_text_overrides;
154 -
155 - if ( ! isset( $fs_text_overrides ) ) {
156 - $fs_text_overrides = array();
157 - }
158 -
152 + if ( ! function_exists( 'fs_get_ip' ) ) {
159 153 /**
160 - * Retrieve a translated text by key.
161 - *
162 - * @deprecated Use `fs_text()` instead since methods starting with `__` trigger warnings in Php 7.
163 - * @todo Remove this method in the future.
164 - *
165 - * @author Vova Feldman (@svovaf)
166 - * @since 1.1.4
167 - *
168 - * @param string $key
169 - * @param string $slug
170 - *
171 - * @return string
172 - *
173 - * @global $fs_text, $fs_text_overrides
174 - */
175 - function __fs( $key, $slug = 'freemius' ) {
176 - _deprecated_function( __FUNCTION__, '2.0.0', 'fs_text()' );
177 -
178 - global $fs_text,
179 - $fs_module_info_text,
180 - $fs_text_overrides;
181 -
182 - if ( isset( $fs_text_overrides[ $slug ] ) ) {
183 - if ( isset( $fs_text_overrides[ $slug ][ $key ] ) ) {
184 - return $fs_text_overrides[ $slug ][ $key ];
185 - }
186 -
187 - $lower_key = strtolower( $key );
188 - if ( isset( $fs_text_overrides[ $slug ][ $lower_key ] ) ) {
189 - return $fs_text_overrides[ $slug ][ $lower_key ];
190 - }
191 - }
192 -
193 - if ( ! isset( $fs_text ) ) {
194 - $dir = defined( 'WP_FS__DIR_INCLUDES' ) ?
195 - WP_FS__DIR_INCLUDES :
196 - dirname( __FILE__ );
197 -
198 - require_once $dir . '/i18n.php';
199 - }
200 -
201 - if ( isset( $fs_text[ $key ] ) ) {
202 - return $fs_text[ $key ];
203 - }
204 -
205 - if ( isset( $fs_module_info_text[ $key ] ) ) {
206 - return $fs_module_info_text[ $key ];
207 - }
208 -
209 - return $key;
210 - }
211 -
212 - /**
213 - * Output a translated text by key.
214 - *
215 - * @deprecated Use `fs_echo()` instead for consistency with `fs_text()`.
216 - *
217 - * @todo Remove this method in the future.
154 + * Get server IP.
218 155 *
219 - * @author Vova Feldman (@svovaf)
220 - * @since 1.1.4
221 - *
222 - * @param string $key
223 - * @param string $slug
224 - */
225 - function _efs( $key, $slug = 'freemius' ) {
226 - fs_echo( $key, $slug );
227 - }
228 - }
229 -
230 - if ( ! function_exists( 'fs_get_ip' ) ) {
231 - /**
232 - * Get client IP.
233 - *
156 + * @since 2.5.1 This method returns the server IP.
157 + *
234 158 * @author Vova Feldman (@svovaf)
235 159 * @since 1.1.2
236 160 *
237 161 * @return string|null
@@ -236,265 +160,259 @@
236 160 *
237 161 * @return string|null
238 162 */
239 163 function fs_get_ip() {
240 - $fields = array(
241 - 'HTTP_CF_CONNECTING_IP',
242 - 'HTTP_CLIENT_IP',
243 - 'HTTP_X_FORWARDED_FOR',
244 - 'HTTP_X_FORWARDED',
245 - 'HTTP_FORWARDED_FOR',
246 - 'HTTP_FORWARDED',
247 - 'REMOTE_ADDR',
248 - );
249 -
250 - foreach ( $fields as $ip_field ) {
251 - if ( ! empty( $_SERVER[ $ip_field ] ) ) {
252 - return $_SERVER[ $ip_field ];
253 - }
254 - }
255 -
256 - return null;
164 + return empty( $_SERVER[ 'SERVER_ADDR' ] ) ?
165 + null :
166 + $_SERVER[ 'SERVER_ADDR' ];
257 167 }
258 168 }
259 169
260 - /**
261 - * Leverage backtrace to find caller plugin main file path.
262 - *
263 - * @author Vova Feldman (@svovaf)
264 - * @since 1.0.6
265 - *
266 - * @return string
267 - */
268 - function fs_find_caller_plugin_file() {
269 - /**
270 - * All the code below will be executed once on activation.
271 - * If the user changes the main plugin's file name, the file_exists()
272 - * will catch it.
273 - */
274 - if ( ! function_exists( 'get_plugins' ) ) {
275 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
276 - }
170 + if ( ! function_exists( 'fs_find_caller_plugin_file' ) ) {
171 + /**
172 + * Leverage backtrace to find caller plugin main file path.
173 + *
174 + * @author Vova Feldman (@svovaf)
175 + * @since 1.0.6
176 + *
177 + * @return string
178 + */
179 + function fs_find_caller_plugin_file() {
180 + /**
181 + * All the code below will be executed once on activation.
182 + * If the user changes the main plugin's file name, the file_exists()
183 + * will catch it.
184 + */
185 + if ( ! function_exists( 'get_plugins' ) ) {
186 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
187 + }
277 188
278 - $all_plugins = fs_get_plugins( true );
279 - $all_plugins_paths = array();
189 + $all_plugins = fs_get_plugins( true );
190 + $all_plugins_paths = array();
280 191
281 - // Get active plugin's main files real full names (might be symlinks).
282 - foreach ( $all_plugins as $relative_path => $data ) {
283 - $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
284 - }
192 + // Get active plugin's main files real full names (might be symlinks).
193 + foreach ( $all_plugins as $relative_path => $data ) {
194 + $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
195 + }
285 196
286 - $plugin_file = null;
287 - for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
288 - if ( empty( $bt[ $i ]['file'] ) ) {
289 - continue;
290 - }
197 + $plugin_file = null;
198 + for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
199 + if ( empty( $bt[ $i ]['file'] ) ) {
200 + continue;
201 + }
291 202
292 - if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) {
293 - $plugin_file = $bt[ $i ]['file'];
294 - break;
295 - }
296 - }
203 + if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) {
204 + $plugin_file = $bt[ $i ]['file'];
205 + break;
206 + }
207 + }
297 208
298 - if ( is_null( $plugin_file ) ) {
299 - // Throw an error to the developer in case of some edge case dev environment.
300 - wp_die(
301 - 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.',
302 - 'Error',
303 - array( 'back_link' => true )
304 - );
305 - }
209 + if ( is_null( $plugin_file ) ) {
210 + // Throw an error to the developer in case of some edge case dev environment.
211 + wp_die(
212 + 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.',
213 + 'Error',
214 + array( 'back_link' => true )
215 + );
216 + }
306 217
307 - return $plugin_file;
308 - }
218 + return $plugin_file;
219 + }
220 + }
309 221
310 222 require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-1.1.7.1.php';
311 223
312 - /**
313 - * Update SDK newest version reference.
314 - *
315 - * @author Vova Feldman (@svovaf)
316 - * @since 1.1.6
317 - *
318 - * @param string $sdk_relative_path
319 - * @param string|bool $plugin_file
320 - *
321 - * @global $fs_active_plugins
322 - */
323 - function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) {
324 - /**
325 - * If there is a plugin running an older version of FS (1.2.1 or below), the `fs_update_sdk_newest_version()`
326 - * function in the older version will be used instead of this one. But since the older version is using
327 - * the `is_plugin_active` function to check if a plugin is active, passing the theme's `plugin_path` to the
328 - * `is_plugin_active` function will return false since the path is not a plugin path, so `in_activation` will be
329 - * `true` for theme modules and the upgrading of the SDK version to 1.2.2 or newer version will work fine.
330 - *
331 - * Future versions that will call this function will use the proper logic here instead of just relying on the
332 - * `is_plugin_active` function to fail for themes.
333 - *
334 - * @author Leo Fajardo (@leorw)
335 - * @since 1.2.2
336 - */
224 + if ( ! function_exists( 'fs_update_sdk_newest_version' ) ) {
225 + /**
226 + * Update SDK newest version reference.
227 + *
228 + * @author Vova Feldman (@svovaf)
229 + * @since 1.1.6
230 + *
231 + * @param string $sdk_relative_path
232 + * @param string|bool $plugin_file
233 + *
234 + * @global $fs_active_plugins
235 + */
236 + function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) {
237 + /**
238 + * If there is a plugin running an older version of FS (1.2.1 or below), the `fs_update_sdk_newest_version()`
239 + * function in the older version will be used instead of this one. But since the older version is using
240 + * the `is_plugin_active` function to check if a plugin is active, passing the theme's `plugin_path` to the
241 + * `is_plugin_active` function will return false since the path is not a plugin path, so `in_activation` will be
242 + * `true` for theme modules and the upgrading of the SDK version to 1.2.2 or newer version will work fine.
243 + *
244 + * Future versions that will call this function will use the proper logic here instead of just relying on the
245 + * `is_plugin_active` function to fail for themes.
246 + *
247 + * @author Leo Fajardo (@leorw)
248 + * @since 1.2.2
249 + */
337 250
338 - global $fs_active_plugins;
251 + global $fs_active_plugins;
339 252
340 - $newest_sdk = $fs_active_plugins->plugins[ $sdk_relative_path ];
253 + $newest_sdk = $fs_active_plugins->plugins[ $sdk_relative_path ];
341 254
342 - if ( ! is_string( $plugin_file ) ) {
343 - $plugin_file = plugin_basename( fs_find_caller_plugin_file() );
344 - }
345 -
346 - if ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) {
347 - if ( ! function_exists( 'is_plugin_active' ) ) {
348 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
255 + if ( ! is_string( $plugin_file ) ) {
256 + $plugin_file = plugin_basename( fs_find_caller_plugin_file() );
349 257 }
350 258
351 - $in_activation = ( ! is_plugin_active( $plugin_file ) );
352 - } else {
353 - $theme = wp_get_theme();
354 - $in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet );
355 - }
259 + if ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) {
260 + if ( ! function_exists( 'is_plugin_active' ) ) {
261 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
262 + }
356 263
357 - $fs_active_plugins->newest = (object) array(
358 - 'plugin_path' => $plugin_file,
359 - 'sdk_path' => $sdk_relative_path,
360 - 'version' => $newest_sdk->version,
361 - 'in_activation' => $in_activation,
362 - 'timestamp' => time(),
363 - );
264 + $in_activation = ( ! is_plugin_active( $plugin_file ) );
265 + } else {
266 + $theme = wp_get_theme();
267 + $in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet );
268 + }
364 269
365 - // Update DB with latest SDK version and path.
366 - update_option( 'fs_active_plugins', $fs_active_plugins );
367 - }
270 + $fs_active_plugins->newest = (object) array(
271 + 'plugin_path' => $plugin_file,
272 + 'sdk_path' => $sdk_relative_path,
273 + 'version' => $newest_sdk->version,
274 + 'in_activation' => $in_activation,
275 + 'timestamp' => time(),
276 + );
368 277
369 - /**
370 - * Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first.
371 - *
372 - * @author Vova Feldman (@svovaf)
373 - * @since 1.1.6
374 - *
375 - * @return bool Was plugin order changed. Return false if plugin was loaded first anyways.
376 - *
377 - * @global $fs_active_plugins
378 - */
379 - function fs_newest_sdk_plugin_first() {
380 - global $fs_active_plugins;
278 + // Update DB with latest SDK version and path.
279 + update_option( 'fs_active_plugins', $fs_active_plugins );
280 + }
281 + }
381 282
283 + if ( ! function_exists( 'fs_newest_sdk_plugin_first' ) ) {
382 284 /**
383 - * @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).
285 + * Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first.
384 286 *
385 - * @link https://github.com/Freemius/wordpress-sdk/issues/26
287 + * @author Vova Feldman (@svovaf)
288 + * @since 1.1.6
289 + *
290 + * @return bool Was plugin order changed. Return false if plugin was loaded first anyways.
291 + *
292 + * @global $fs_active_plugins
386 293 */
294 + function fs_newest_sdk_plugin_first() {
295 + global $fs_active_plugins;
387 296
388 - $newest_sdk_plugin_path = $fs_active_plugins->newest->plugin_path;
297 + /**
298 + * @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).
299 + *
300 + * @link https://github.com/Freemius/wordpress-sdk/issues/26
301 + */
389 302
390 - $active_plugins = get_option( 'active_plugins', array() );
391 - $updated_active_plugins = array( $newest_sdk_plugin_path );
303 + $newest_sdk_plugin_path = $fs_active_plugins->newest->plugin_path;
392 304
393 - $plugin_found = false;
394 - $is_first_path = true;
305 + $active_plugins = get_option( 'active_plugins', array() );
306 + $updated_active_plugins = array( $newest_sdk_plugin_path );
395 307
396 - foreach ( $active_plugins as $key => $plugin_path ) {
397 - if ( $plugin_path === $newest_sdk_plugin_path ) {
398 - if ( $is_first_path ) {
399 - // if it's the first plugin already, no need to continue
400 - return false;
308 + $plugin_found = false;
309 + $is_first_path = true;
310 +
311 + foreach ( $active_plugins as $key => $plugin_path ) {
312 + if ( $plugin_path === $newest_sdk_plugin_path ) {
313 + if ( $is_first_path ) {
314 + // if it's the first plugin already, no need to continue
315 + return false;
316 + }
317 +
318 + $plugin_found = true;
319 +
320 + // Skip the plugin (it is already added as the 1st item of $updated_active_plugins).
321 + continue;
401 322 }
402 323
403 - $plugin_found = true;
324 + $updated_active_plugins[] = $plugin_path;
404 325
405 - // Skip the plugin (it is already added as the 1st item of $updated_active_plugins).
406 - continue;
326 + if ( $is_first_path ) {
327 + $is_first_path = false;
328 + }
407 329 }
408 330
409 - $updated_active_plugins[] = $plugin_path;
331 + if ( $plugin_found ) {
332 + update_option( 'active_plugins', $updated_active_plugins );
410 333
411 - if ( $is_first_path ) {
412 - $is_first_path = false;
334 + return true;
413 335 }
414 - }
415 336
416 - if ( $plugin_found ) {
417 - update_option( 'active_plugins', $updated_active_plugins );
337 + if ( is_multisite() ) {
338 + // Plugin is network active.
339 + $network_active_plugins = get_site_option( 'active_sitewide_plugins', array() );
418 340
419 - return true;
420 - }
341 + if ( isset( $network_active_plugins[ $newest_sdk_plugin_path ] ) ) {
342 + reset( $network_active_plugins );
343 + if ( $newest_sdk_plugin_path === key( $network_active_plugins ) ) {
344 + // Plugin is already activated first on the network level.
345 + return false;
346 + } else {
347 + $time = $network_active_plugins[ $newest_sdk_plugin_path ];
421 348
422 - if ( is_multisite() ) {
423 - // Plugin is network active.
424 - $network_active_plugins = get_site_option( 'active_sitewide_plugins', array() );
349 + // Remove plugin from its current position.
350 + unset( $network_active_plugins[ $newest_sdk_plugin_path ] );
425 351
426 - if ( isset( $network_active_plugins[ $newest_sdk_plugin_path ] ) ) {
427 - reset( $network_active_plugins );
428 - if ( $newest_sdk_plugin_path === key( $network_active_plugins ) ) {
429 - // Plugin is already activated first on the network level.
430 - return false;
431 - } else {
432 - $time = $network_active_plugins[ $newest_sdk_plugin_path ];
352 + // Set it to be included first.
353 + $network_active_plugins = array( $newest_sdk_plugin_path => $time ) + $network_active_plugins;
433 354
434 - // Remove plugin from its current position.
435 - unset( $network_active_plugins[ $newest_sdk_plugin_path ] );
355 + update_site_option( 'active_sitewide_plugins', $network_active_plugins );
436 356
437 - // Set it to be included first.
438 - $network_active_plugins = array( $newest_sdk_plugin_path => $time ) + $network_active_plugins;
439 -
440 - update_site_option( 'active_sitewide_plugins', $network_active_plugins );
441 -
442 - return true;
357 + return true;
358 + }
443 359 }
444 360 }
361 +
362 + return false;
445 363 }
446 -
447 - return false;
448 364 }
449 365
450 - /**
451 - * Go over all Freemius SDKs in the system and find and "remember"
452 - * the newest SDK which is associated with an active plugin.
453 - *
454 - * @author Vova Feldman (@svovaf)
455 - * @since 1.1.6
456 - *
457 - * @global $fs_active_plugins
458 - */
459 - function fs_fallback_to_newest_active_sdk() {
460 - global $fs_active_plugins;
366 + if ( ! function_exists( 'fs_fallback_to_newest_active_sdk' ) ) {
367 + /**
368 + * Go over all Freemius SDKs in the system and find and "remember"
369 + * the newest SDK which is associated with an active plugin.
370 + *
371 + * @author Vova Feldman (@svovaf)
372 + * @since 1.1.6
373 + *
374 + * @global $fs_active_plugins
375 + */
376 + function fs_fallback_to_newest_active_sdk() {
377 + global $fs_active_plugins;
461 378
462 - /**
463 - * @var object $newest_sdk_data
464 - */
465 - $newest_sdk_data = null;
466 - $newest_sdk_path = null;
379 + /**
380 + * @var object $newest_sdk_data
381 + */
382 + $newest_sdk_data = null;
383 + $newest_sdk_path = null;
467 384
468 - foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) {
469 - if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' )
470 - ) {
471 - // If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
472 - if ( 'plugin' === $data->type ) {
473 - $is_module_active = is_plugin_active( $data->plugin_path );
474 - } else {
475 - $active_theme = wp_get_theme();
476 - $is_module_active = ( $data->plugin_path === $active_theme->get_template() );
477 - }
385 + foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) {
386 + if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' )
387 + ) {
388 + // If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
389 + if ( 'plugin' === $data->type ) {
390 + $is_module_active = is_plugin_active( $data->plugin_path );
391 + } else {
392 + $active_theme = wp_get_theme();
393 + $is_module_active = ( $data->plugin_path === $active_theme->get_template() );
394 + }
478 395
479 - $is_sdk_exists = file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) );
396 + $is_sdk_exists = file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) );
480 397
481 - if ( ! $is_module_active || ! $is_sdk_exists ) {
482 - unset( $fs_active_plugins->plugins[ $sdk_relative_path ] );
398 + if ( ! $is_module_active || ! $is_sdk_exists ) {
399 + unset( $fs_active_plugins->plugins[ $sdk_relative_path ] );
483 400
484 - // No need to store the data since it will be stored in fs_update_sdk_newest_version()
485 - // or explicitly with update_option().
486 - } else {
487 - $newest_sdk_data = $data;
488 - $newest_sdk_path = $sdk_relative_path;
489 - }
490 - }
491 - }
401 + // No need to store the data since it will be stored in fs_update_sdk_newest_version()
402 + // or explicitly with update_option().
403 + } else {
404 + $newest_sdk_data = $data;
405 + $newest_sdk_path = $sdk_relative_path;
406 + }
407 + }
408 + }
492 409
493 - if ( is_null( $newest_sdk_data ) ) {
494 - // Couldn't find any SDK reference.
495 - $fs_active_plugins = new stdClass();
496 - update_option( 'fs_active_plugins', $fs_active_plugins );
497 - } else {
498 - fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
499 - }
500 - }
410 + if ( is_null( $newest_sdk_data ) ) {
411 + // Couldn't find any SDK reference.
412 + $fs_active_plugins = new stdClass();
413 + update_option( 'fs_active_plugins', $fs_active_plugins );
414 + } else {
415 + fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
416 + }
417 + }
418 + }