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