PluginProbe
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder / 1.4.4
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder v1.4.4
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
buttonizer-multifunctional-button / freemius / start.php

start.php in Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder 1.4.4, at freemius/start.php

502 lines 17.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Freemius
4 * @copyright Copyright (c) 2015, Freemius, Inc.
5 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6 * @since 1.0.3
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Freemius SDK Version.
15 *
16 * @var string
17 */
18 $this_sdk_version = '1.2.4';
19
20 #region SDK Selection Logic --------------------------------------------------------------------
21
22 /**
23 * Special logic added on 1.1.6 to make sure that every Freemius powered plugin
24 * will ALWAYS be loaded with the newest SDK from the active Freemius powered plugins.
25 *
26 * Since Freemius SDK is backward compatible, this will make sure that all Freemius powered
27 * plugins will run correctly.
28 *
29 * @since 1.1.6
30 */
31
32 global $fs_active_plugins;
33
34 if ( ! function_exists( 'fs_find_caller_plugin_file' ) ) {
35 // Require SDK essentials.
36 require_once dirname( __FILE__ ) . '/includes/fs-essential-functions.php';
37 }
38
39 /**
40 * This complex logic fixes symlink issues (e.g. with Vargant). The logic assumes
41 * that if it's a file from an SDK running in a theme, the location of the SDK
42 * is in the main theme's folder.
43 *
44 * @author Vova Feldman (@svovaf)
45 * @since 1.2.2.6
46 */
47 $file_path = fs_normalize_path( __FILE__ );
48 $fs_root_path = dirname( $file_path );
49 $themes_directory = get_theme_root();
50 $themes_directory_name = basename( $themes_directory );
51 $theme_candidate_basename = basename( dirname( $fs_root_path ) ) . '/' . basename( $fs_root_path );
52
53 if ( $file_path == fs_normalize_path( realpath( trailingslashit( $themes_directory ) . $theme_candidate_basename . '/' . basename( $file_path ) ) )
54 ) {
55 $this_sdk_relative_path = '../' . $themes_directory_name . '/' . $theme_candidate_basename;
56 $is_theme = true;
57 } else {
58 $this_sdk_relative_path = plugin_basename( $fs_root_path );
59 $is_theme = false;
60 }
61
62 if ( ! isset( $fs_active_plugins ) ) {
63 // Load all Freemius powered active plugins.
64 $fs_active_plugins = get_option( 'fs_active_plugins', new stdClass() );
65
66 if ( ! isset( $fs_active_plugins->plugins ) ) {
67 $fs_active_plugins->plugins = array();
68 }
69 }
70
71 if ( empty( $fs_active_plugins->abspath ) ) {
72 /**
73 * Store the WP install absolute path reference to identify environment change
74 * while replicating the storage.
75 *
76 * @author Vova Feldman (@svovaf)
77 * @since 1.2.1.7
78 */
79 $fs_active_plugins->abspath = ABSPATH;
80 } else {
81 if ( ABSPATH !== $fs_active_plugins->abspath ) {
82 /**
83 * WordPress path has changed, cleanup the SDK references cache.
84 * This resolves issues triggered when spinning a staging environments
85 * while replicating the database.
86 *
87 * @author Vova Feldman (@svovaf)
88 * @since 1.2.1.7
89 */
90 $fs_active_plugins->abspath = ABSPATH;
91 $fs_active_plugins->plugins = array();
92 unset( $fs_active_plugins->newest );
93 } else {
94 /**
95 * Make sure SDK references are still valid. This resolves
96 * issues when users hard delete modules via FTP.
97 *
98 * @author Vova Feldman (@svovaf)
99 * @since 1.2.1.7
100 */
101 $has_changes = false;
102 foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
103 if ( ! file_exists( WP_PLUGIN_DIR . '/' . $sdk_path ) ) {
104 unset( $fs_active_plugins->plugins[ $sdk_path ] );
105 $has_changes = true;
106 }
107 }
108
109 if ( $has_changes ) {
110 if ( empty( $fs_active_plugins->plugins ) ) {
111 unset( $fs_active_plugins->newest );
112 }
113
114 update_option( 'fs_active_plugins', $fs_active_plugins );
115 }
116 }
117 }
118
119 if ( ! function_exists( 'fs_find_direct_caller_plugin_file' ) ) {
120 require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-1.1.7.1.php';
121 }
122
123 // Update current SDK info based on the SDK path.
124 if ( ! isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) ||
125 $this_sdk_version != $fs_active_plugins->plugins[ $this_sdk_relative_path ]->version
126 ) {
127 if ( $is_theme ) {
128 $plugin_path = basename( dirname( $this_sdk_relative_path ) );
129 } else {
130 $plugin_path = plugin_basename( fs_find_direct_caller_plugin_file( $file_path ) );
131 }
132
133 $fs_active_plugins->plugins[ $this_sdk_relative_path ] = (object) array(
134 'version' => $this_sdk_version,
135 'type' => ( $is_theme ? 'theme' : 'plugin' ),
136 'timestamp' => time(),
137 'plugin_path' => $plugin_path,
138 );
139 }
140
141 $is_current_sdk_newest = isset( $fs_active_plugins->newest ) && ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path );
142
143 if ( ! isset( $fs_active_plugins->newest ) ) {
144 /**
145 * This will be executed only once, for the first time a Freemius powered plugin is activated.
146 */
147 fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
148
149 $is_current_sdk_newest = true;
150 } else if ( version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '<' ) ) {
151 /**
152 * Current SDK is newer than the newest stored SDK.
153 */
154 fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
155
156 if ( class_exists( 'Freemius' ) ) {
157 // Older SDK version was already loaded.
158
159 if ( ! $fs_active_plugins->newest->in_activation ) {
160 // Re-order plugins to load this plugin first.
161 fs_newest_sdk_plugin_first();
162 }
163
164 // Refresh page.
165 fs_redirect( $_SERVER['REQUEST_URI'] );
166 }
167 } else {
168 if ( ! function_exists( 'get_plugins' ) ) {
169 require_once ABSPATH . 'wp-admin/includes/plugin.php';
170 }
171
172 $fs_newest_sdk = $fs_active_plugins->newest;
173 $fs_newest_sdk = $fs_active_plugins->plugins[ $fs_newest_sdk->sdk_path ];
174
175 $is_newest_sdk_type_theme = ( isset( $fs_newest_sdk->type ) && 'theme' === $fs_newest_sdk->type );
176
177 if ( ! $is_newest_sdk_type_theme ) {
178 $is_newest_sdk_plugin_active = is_plugin_active( $fs_newest_sdk->plugin_path );
179 } else {
180 $current_theme = wp_get_theme();
181 $is_newest_sdk_plugin_active = ( $current_theme->stylesheet === $fs_newest_sdk->plugin_path );
182 }
183
184 if ( $is_current_sdk_newest &&
185 ! $is_newest_sdk_plugin_active &&
186 ! $fs_active_plugins->newest->in_activation
187 ) {
188 // If current SDK is the newest and the plugin is NOT active, it means
189 // that the current plugin in activation mode.
190 $fs_active_plugins->newest->in_activation = true;
191 update_option( 'fs_active_plugins', $fs_active_plugins );
192 }
193
194 if ( ! $is_theme ) {
195 $sdk_starter_path = fs_normalize_path( WP_PLUGIN_DIR . '/' . $this_sdk_relative_path . '/start.php' );
196 } else {
197 $sdk_starter_path = fs_normalize_path(
198 get_theme_root()
199 . '/'
200 . str_replace( "../{$themes_directory_name}/", '', $this_sdk_relative_path )
201 . '/start.php' );
202 }
203
204 $is_newest_sdk_path_valid = ( $is_newest_sdk_plugin_active || $fs_active_plugins->newest->in_activation ) && file_exists( $sdk_starter_path );
205
206 if ( ! $is_newest_sdk_path_valid && ! $is_current_sdk_newest ) {
207 // Plugin with newest SDK is no longer active, or SDK was moved to a different location.
208 unset( $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ] );
209 }
210
211 if ( ! ( $is_newest_sdk_plugin_active || $fs_active_plugins->newest->in_activation ) ||
212 ! $is_newest_sdk_path_valid ||
213 // Is newest SDK downgraded.
214 ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
215 version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '>' ) )
216 ) {
217 /**
218 * Plugin with newest SDK is no longer active.
219 * OR
220 * The newest SDK was in the current plugin. BUT, seems like the version of
221 * the SDK was downgraded to a lower SDK.
222 */
223 // Find the active plugin with the newest SDK version and update the newest reference.
224 fs_fallback_to_newest_active_sdk();
225 } else {
226 if ( $is_newest_sdk_plugin_active &&
227 $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
228 ( $fs_active_plugins->newest->in_activation ||
229 ( class_exists( 'Freemius' ) && ( ! defined( 'WP_FS__SDK_VERSION' ) || version_compare( WP_FS__SDK_VERSION, $this_sdk_version, '<' ) ) )
230 )
231
232 ) {
233 if ( $fs_active_plugins->newest->in_activation && ! $is_newest_sdk_type_theme ) {
234 // Plugin no more in activation.
235 $fs_active_plugins->newest->in_activation = false;
236 update_option( 'fs_active_plugins', $fs_active_plugins );
237 }
238
239 // Reorder plugins to load plugin with newest SDK first.
240 if ( fs_newest_sdk_plugin_first() ) {
241 // Refresh page after re-order to make sure activated plugin loads newest SDK.
242 if ( class_exists( 'Freemius' ) ) {
243 fs_redirect( $_SERVER['REQUEST_URI'] );
244 }
245 }
246 }
247 }
248 }
249
250 if ( class_exists( 'Freemius' ) ) {
251 // SDK was already loaded.
252 return;
253 }
254
255 if ( version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) {
256 $newest_sdk = $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ];
257
258 $plugins_or_theme_dir_path = ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) ?
259 WP_PLUGIN_DIR :
260 get_theme_root();
261
262 $newest_sdk_starter = fs_normalize_path(
263 $plugins_or_theme_dir_path
264 . '/'
265 . str_replace( "../{$themes_directory_name}/", '', $fs_active_plugins->newest->sdk_path )
266 . '/start.php' );
267
268 if ( file_exists( $newest_sdk_starter ) ) {
269 // Reorder plugins to load plugin with newest SDK first.
270 fs_newest_sdk_plugin_first();
271
272 // There's a newer SDK version, load it instead of the current one!
273 require_once $newest_sdk_starter;
274
275 return;
276 }
277 }
278
279 #endregion SDK Selection Logic --------------------------------------------------------------------
280
281 #region Hooks & Filters Collection --------------------------------------------------------------------
282
283 /**
284 * Freemius hooks (actions & filters) tags structure:
285 *
286 * fs_{filter/action_name}_{plugin_slug}
287 *
288 * --------------------------------------------------------
289 *
290 * Usage with WordPress' add_action() / add_filter():
291 *
292 * add_action('fs_{filter/action_name}_{plugin_slug}', $callable);
293 *
294 * --------------------------------------------------------
295 *
296 * Usage with Freemius' instance add_action() / add_filter():
297 *
298 * // No need to add 'fs_' prefix nor '_{plugin_slug}' suffix.
299 * my_freemius()->add_action('{action_name}', $callable);
300 *
301 * --------------------------------------------------------
302 *
303 * Freemius filters collection:
304 *
305 * fs_connect_url_{plugin_slug}
306 * fs_trial_promotion_message_{plugin_slug}
307 * fs_is_long_term_user_{plugin_slug}
308 * fs_uninstall_reasons_{plugin_slug}
309 * fs_is_plugin_update_{plugin_slug}
310 * fs_api_domains_{plugin_slug}
311 * fs_email_template_sections_{plugin_slug}
312 * fs_support_forum_submenu_{plugin_slug}
313 * fs_support_forum_url_{plugin_slug}
314 * fs_connect_message_{plugin_slug}
315 * fs_connect_message_on_update_{plugin_slug}
316 * fs_uninstall_confirmation_message_{plugin_slug}
317 * fs_pending_activation_message_{plugin_slug}
318 * fs_is_submenu_visible_{plugin_slug}
319 * fs_plugin_icon_{plugin_slug}
320 * fs_show_trial_{plugin_slug}
321 *
322 * --------------------------------------------------------
323 *
324 * Freemius actions collection:
325 *
326 * fs_after_license_loaded_{plugin_slug}
327 * fs_after_license_change_{plugin_slug}
328 * fs_after_plans_sync_{plugin_slug}
329 *
330 * fs_after_account_details_{plugin_slug}
331 * fs_after_account_user_sync_{plugin_slug}
332 * fs_after_account_plan_sync_{plugin_slug}
333 * fs_before_account_load_{plugin_slug}
334 * fs_after_account_connection_{plugin_slug}
335 * fs_account_property_edit_{plugin_slug}
336 * fs_account_email_verified_{plugin_slug}
337 * fs_account_page_load_before_departure_{plugin_slug}
338 * fs_before_account_delete_{plugin_slug}
339 * fs_after_account_delete_{plugin_slug}
340 *
341 * fs_sdk_version_update_{plugin_slug}
342 * fs_plugin_version_update_{plugin_slug}
343 *
344 * fs_initiated_{plugin_slug}
345 * fs_after_init_plugin_registered_{plugin_slug}
346 * fs_after_init_plugin_anonymous_{plugin_slug}
347 * fs_after_init_plugin_pending_activations_{plugin_slug}
348 * fs_after_init_addon_registered_{plugin_slug}
349 * fs_after_init_addon_anonymous_{plugin_slug}
350 * fs_after_init_addon_pending_activations_{plugin_slug}
351 *
352 * fs_after_premium_version_activation_{plugin_slug}
353 * fs_after_free_version_reactivation_{plugin_slug}
354 *
355 * fs_after_uninstall_{plugin_slug}
356 * fs_before_admin_menu_init_{plugin_slug}
357 */
358
359 #endregion Hooks & Filters Collection --------------------------------------------------------------------
360
361 if ( ! class_exists( 'Freemius' ) ) {
362
363 if ( ! defined( 'WP_FS__SDK_VERSION' ) ) {
364 define( 'WP_FS__SDK_VERSION', $this_sdk_version );
365 }
366
367 $plugins_or_theme_dir_path = fs_normalize_path( trailingslashit( $is_theme ?
368 get_theme_root() :
369 WP_PLUGIN_DIR ) );
370
371 if ( 0 === strpos( $file_path, $plugins_or_theme_dir_path ) ) {
372 // No symlinks
373 } else {
374 /**
375 * This logic finds the SDK symlink and set WP_FS__DIR to use it.
376 *
377 * @author Vova Feldman (@svovaf)
378 * @since 1.2.2.5
379 */
380 $sdk_symlink = null;
381
382 // Try to load SDK's symlink from cache.
383 if ( isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) &&
384 is_object( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) &&
385 ! empty( $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink )
386 ) {
387 $sdk_symlink = $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink;
388 if ( 0 === strpos( $sdk_symlink, $plugins_or_theme_dir_path ) ) {
389 /**
390 * Make the symlink path relative.
391 *
392 * @author Leo Fajardo (@leorw)
393 */
394 $sdk_symlink = substr( $sdk_symlink, strlen( $plugins_or_theme_dir_path ) );
395
396 $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink = $sdk_symlink;
397 update_option( 'fs_active_plugins', $fs_active_plugins );
398 }
399
400 $realpath = realpath( $plugins_or_theme_dir_path . $sdk_symlink );
401 if ( ! is_string( $realpath ) || ! file_exists( $realpath ) ) {
402 $sdk_symlink = null;
403 }
404 }
405
406 if ( empty( $sdk_symlink ) ) // Has symlinks, therefore, we need to configure WP_FS__DIR based on the symlink.
407 {
408 $partial_path_right = basename( $file_path );
409 $partial_path_left = dirname( $file_path );
410 $realpath = realpath( $plugins_or_theme_dir_path . $partial_path_right );
411
412 while ( '/' !== $partial_path_left &&
413 ( false === $realpath || $file_path !== fs_normalize_path( $realpath ) )
414 ) {
415 $partial_path_right = trailingslashit( basename( $partial_path_left ) ) . $partial_path_right;
416 $partial_path_left_prev = $partial_path_left;
417 $partial_path_left = dirname( $partial_path_left_prev );
418
419 /**
420 * Avoid infinite loop if for example `$partial_path_left_prev` is `C:/`, in this case,
421 * `dirname( 'C:/' )` will return `C:/`.
422 *
423 * @author Leo Fajardo (@leorw)
424 */
425 if ( $partial_path_left === $partial_path_left_prev ) {
426 $partial_path_left = '';
427 break;
428 }
429
430 $realpath = realpath( $plugins_or_theme_dir_path . $partial_path_right );
431 }
432
433 if ( ! empty( $partial_path_left ) && '/' !== $partial_path_left ) {
434 $sdk_symlink = fs_normalize_path( dirname( $partial_path_right ) );
435
436 // Cache value.
437 if ( isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) &&
438 is_object( $fs_active_plugins->plugins[ $this_sdk_relative_path ] )
439 ) {
440 $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink = $sdk_symlink;
441 update_option( 'fs_active_plugins', $fs_active_plugins );
442 }
443 }
444 }
445
446 if ( ! empty( $sdk_symlink ) ) {
447 // Set SDK dir to the symlink path.
448 define( 'WP_FS__DIR', $plugins_or_theme_dir_path . $sdk_symlink );
449 }
450 }
451
452 // Load SDK files.
453 require_once dirname( __FILE__ ) . '/require.php';
454
455 /**
456 * Quick shortcut to get Freemius for specified plugin.
457 * Used by various templates.
458 *
459 * @param number $module_id
460 *
461 * @return Freemius
462 */
463 function freemius( $module_id ) {
464 return Freemius::instance( $module_id );
465 }
466
467 /**
468 * @param string $slug
469 * @param number $plugin_id
470 * @param string $public_key
471 * @param bool $is_live Is live or test plugin.
472 * @param bool $is_premium Hints freemius if running the premium plugin or not.
473 *
474 * @return Freemius
475 *
476 * @deprecated Please use fs_dynamic_init().
477 */
478 function fs_init( $slug, $plugin_id, $public_key, $is_live = true, $is_premium = true ) {
479 $fs = Freemius::instance( $plugin_id, $slug, true );
480 $fs->init( $plugin_id, $public_key, $is_live, $is_premium );
481
482 return $fs;
483 }
484
485 /**
486 * @param array <string,string> $module Plugin or Theme details.
487 *
488 * @return Freemius
489 * @throws Freemius_Exception
490 */
491 function fs_dynamic_init( $module ) {
492 $fs = Freemius::instance( $module['id'], $module['slug'], true );
493 $fs->dynamic_init( $module );
494
495 return $fs;
496 }
497
498 function fs_dump_log() {
499 FS_Logger::dump();
500 }
501 }
502