PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.7.31.4
Pods – Custom Content Types and Fields v2.7.31.4
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / vendor / freemius / wordpress-sdk / start.php
pods / vendor / freemius / wordpress-sdk Last commit date
assets 1 week ago includes 1 week ago languages 1 week ago templates 1 week ago LICENSE.txt 1 week ago config.php 1 week ago index.php 1 week ago require.php 1 week ago start.php 1 week ago
start.php
536 lines
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 = '2.4.2';
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 /**
50 * Get the themes directory where the active theme is located (not passing the stylesheet will make WordPress
51 * assume that the themes directory is inside `wp-content`.
52 *
53 * @author Leo Fajardo (@leorw)
54 * @since 2.2.3
55 */
56 $themes_directory = get_theme_root( get_stylesheet() );
57 $themes_directory_name = basename( $themes_directory );
58 $theme_candidate_basename = basename( dirname( $fs_root_path ) ) . '/' . basename( $fs_root_path );
59
60 if ( $file_path == fs_normalize_path( realpath( trailingslashit( $themes_directory ) . $theme_candidate_basename . '/' . basename( $file_path ) ) )
61 ) {
62 $this_sdk_relative_path = '../' . $themes_directory_name . '/' . $theme_candidate_basename;
63 $is_theme = true;
64 } else {
65 $this_sdk_relative_path = plugin_basename( $fs_root_path );
66 $is_theme = false;
67 }
68
69 if ( ! isset( $fs_active_plugins ) ) {
70 // Load all Freemius powered active plugins.
71 $fs_active_plugins = get_option( 'fs_active_plugins', new stdClass() );
72
73 // Prevent potential PHP 7.4+ warnings when the option came back with a non-object.
74 if ( ! is_object( $fs_active_plugins ) ) {
75 $fs_active_plugins = new stdClass();
76 }
77
78 if ( ! isset( $fs_active_plugins->plugins ) ) {
79 $fs_active_plugins->plugins = array();
80 }
81 }
82
83 if ( empty( $fs_active_plugins->abspath ) ) {
84 /**
85 * Store the WP install absolute path reference to identify environment change
86 * while replicating the storage.
87 *
88 * @author Vova Feldman (@svovaf)
89 * @since 1.2.1.7
90 */
91 $fs_active_plugins->abspath = ABSPATH;
92 } else {
93 if ( ABSPATH !== $fs_active_plugins->abspath ) {
94 /**
95 * WordPress path has changed, cleanup the SDK references cache.
96 * This resolves issues triggered when spinning a staging environments
97 * while replicating the database.
98 *
99 * @author Vova Feldman (@svovaf)
100 * @since 1.2.1.7
101 */
102 $fs_active_plugins->abspath = ABSPATH;
103 $fs_active_plugins->plugins = array();
104 unset( $fs_active_plugins->newest );
105 } else {
106 /**
107 * Make sure SDK references are still valid. This resolves
108 * issues when users hard delete modules via FTP.
109 *
110 * @author Vova Feldman (@svovaf)
111 * @since 1.2.1.7
112 */
113 $has_changes = false;
114 foreach ( $fs_active_plugins->plugins as $sdk_path => $data ) {
115 if ( ! file_exists( ( isset( $data->type ) && 'theme' === $data->type ? $themes_directory : WP_PLUGIN_DIR ) . '/' . $sdk_path ) ) {
116 unset( $fs_active_plugins->plugins[ $sdk_path ] );
117
118 if (
119 ! empty( $fs_active_plugins->newest ) &&
120 $sdk_path === $fs_active_plugins->newest->sdk_path
121 ) {
122 unset( $fs_active_plugins->newest );
123 }
124
125 $has_changes = true;
126 }
127 }
128
129 if ( $has_changes ) {
130 if ( empty( $fs_active_plugins->plugins ) ) {
131 unset( $fs_active_plugins->newest );
132 }
133
134 update_option( 'fs_active_plugins', $fs_active_plugins );
135 }
136 }
137 }
138
139 if ( ! function_exists( 'fs_find_direct_caller_plugin_file' ) ) {
140 require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-1.1.7.1.php';
141 }
142
143 if ( ! function_exists( 'fs_get_plugins' ) ) {
144 require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-2.2.1.php';
145 }
146
147 // Update current SDK info based on the SDK path.
148 if ( ! isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) ||
149 $this_sdk_version != $fs_active_plugins->plugins[ $this_sdk_relative_path ]->version
150 ) {
151 if ( $is_theme ) {
152 $plugin_path = basename( dirname( $this_sdk_relative_path ) );
153 } else {
154 $plugin_path = plugin_basename( fs_find_direct_caller_plugin_file( $file_path ) );
155 }
156
157 $fs_active_plugins->plugins[ $this_sdk_relative_path ] = (object) array(
158 'version' => $this_sdk_version,
159 'type' => ( $is_theme ? 'theme' : 'plugin' ),
160 'timestamp' => time(),
161 'plugin_path' => $plugin_path,
162 );
163 }
164
165 $is_current_sdk_newest = isset( $fs_active_plugins->newest ) && ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path );
166
167 if ( ! isset( $fs_active_plugins->newest ) ) {
168 /**
169 * This will be executed only once, for the first time a Freemius powered plugin is activated.
170 */
171 fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
172
173 $is_current_sdk_newest = true;
174 } else if ( version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '<' ) ) {
175 /**
176 * Current SDK is newer than the newest stored SDK.
177 */
178 fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
179
180 if ( class_exists( 'Freemius' ) ) {
181 // Older SDK version was already loaded.
182
183 if ( ! $fs_active_plugins->newest->in_activation ) {
184 // Re-order plugins to load this plugin first.
185 fs_newest_sdk_plugin_first();
186 }
187
188 // Refresh page.
189 fs_redirect( $_SERVER['REQUEST_URI'] );
190 }
191 } else {
192 if ( ! function_exists( 'get_plugins' ) ) {
193 require_once ABSPATH . 'wp-admin/includes/plugin.php';
194 }
195
196 $fs_newest_sdk = $fs_active_plugins->newest;
197 $fs_newest_sdk = $fs_active_plugins->plugins[ $fs_newest_sdk->sdk_path ];
198
199 $is_newest_sdk_type_theme = ( isset( $fs_newest_sdk->type ) && 'theme' === $fs_newest_sdk->type );
200
201 if ( ! $is_newest_sdk_type_theme ) {
202 $is_newest_sdk_plugin_active = is_plugin_active( $fs_newest_sdk->plugin_path );
203 } else {
204 $current_theme = wp_get_theme();
205 $is_newest_sdk_plugin_active = ( $current_theme->stylesheet === $fs_newest_sdk->plugin_path );
206
207 $current_theme_parent = $current_theme->parent();
208
209 /**
210 * If the current theme is a child of the theme that has the newest SDK, this prevents a redirects loop
211 * from happening by keeping the SDK info stored in the `fs_active_plugins` option.
212 */
213 if ( ! $is_newest_sdk_plugin_active && $current_theme_parent instanceof WP_Theme ) {
214 $is_newest_sdk_plugin_active = ( $fs_newest_sdk->plugin_path === $current_theme_parent->stylesheet );
215 }
216 }
217
218 if ( $is_current_sdk_newest &&
219 ! $is_newest_sdk_plugin_active &&
220 ! $fs_active_plugins->newest->in_activation
221 ) {
222 // If current SDK is the newest and the plugin is NOT active, it means
223 // that the current plugin in activation mode.
224 $fs_active_plugins->newest->in_activation = true;
225 update_option( 'fs_active_plugins', $fs_active_plugins );
226 }
227
228 if ( ! $is_theme ) {
229 $sdk_starter_path = fs_normalize_path( WP_PLUGIN_DIR . '/' . $this_sdk_relative_path . '/start.php' );
230 } else {
231 $sdk_starter_path = fs_normalize_path(
232 $themes_directory
233 . '/'
234 . str_replace( "../{$themes_directory_name}/", '', $this_sdk_relative_path )
235 . '/start.php' );
236 }
237
238 $is_newest_sdk_path_valid = ( $is_newest_sdk_plugin_active || $fs_active_plugins->newest->in_activation ) && file_exists( $sdk_starter_path );
239
240 if ( ! $is_newest_sdk_path_valid && ! $is_current_sdk_newest ) {
241 // Plugin with newest SDK is no longer active, or SDK was moved to a different location.
242 unset( $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ] );
243 }
244
245 if ( ! ( $is_newest_sdk_plugin_active || $fs_active_plugins->newest->in_activation ) ||
246 ! $is_newest_sdk_path_valid ||
247 // Is newest SDK downgraded.
248 ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
249 version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '>' ) )
250 ) {
251 /**
252 * Plugin with newest SDK is no longer active.
253 * OR
254 * The newest SDK was in the current plugin. BUT, seems like the version of
255 * the SDK was downgraded to a lower SDK.
256 */
257 // Find the active plugin with the newest SDK version and update the newest reference.
258 fs_fallback_to_newest_active_sdk();
259 } else {
260 if ( $is_newest_sdk_plugin_active &&
261 $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
262 ( $fs_active_plugins->newest->in_activation ||
263 ( class_exists( 'Freemius' ) && ( ! defined( 'WP_FS__SDK_VERSION' ) || version_compare( WP_FS__SDK_VERSION, $this_sdk_version, '<' ) ) )
264 )
265
266 ) {
267 if ( $fs_active_plugins->newest->in_activation && ! $is_newest_sdk_type_theme ) {
268 // Plugin no more in activation.
269 $fs_active_plugins->newest->in_activation = false;
270 update_option( 'fs_active_plugins', $fs_active_plugins );
271 }
272
273 // Reorder plugins to load plugin with newest SDK first.
274 if ( fs_newest_sdk_plugin_first() ) {
275 // Refresh page after re-order to make sure activated plugin loads newest SDK.
276 if ( class_exists( 'Freemius' ) ) {
277 fs_redirect( $_SERVER['REQUEST_URI'] );
278 }
279 }
280 }
281 }
282 }
283
284 if ( class_exists( 'Freemius' ) ) {
285 // SDK was already loaded.
286 return;
287 }
288
289 if ( version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) {
290 $newest_sdk = $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ];
291
292 $plugins_or_theme_dir_path = ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) ?
293 WP_PLUGIN_DIR :
294 $themes_directory;
295
296 $newest_sdk_starter = fs_normalize_path(
297 $plugins_or_theme_dir_path
298 . '/'
299 . str_replace( "../{$themes_directory_name}/", '', $fs_active_plugins->newest->sdk_path )
300 . '/start.php' );
301
302 if ( file_exists( $newest_sdk_starter ) ) {
303 // Reorder plugins to load plugin with newest SDK first.
304 fs_newest_sdk_plugin_first();
305
306 // There's a newer SDK version, load it instead of the current one!
307 require_once $newest_sdk_starter;
308
309 return;
310 }
311 }
312
313 #endregion SDK Selection Logic --------------------------------------------------------------------
314
315 #region Hooks & Filters Collection --------------------------------------------------------------------
316
317 /**
318 * Freemius hooks (actions & filters) tags structure:
319 *
320 * fs_{filter/action_name}_{plugin_slug}
321 *
322 * --------------------------------------------------------
323 *
324 * Usage with WordPress' add_action() / add_filter():
325 *
326 * add_action('fs_{filter/action_name}_{plugin_slug}', $callable);
327 *
328 * --------------------------------------------------------
329 *
330 * Usage with Freemius' instance add_action() / add_filter():
331 *
332 * // No need to add 'fs_' prefix nor '_{plugin_slug}' suffix.
333 * my_freemius()->add_action('{action_name}', $callable);
334 *
335 * --------------------------------------------------------
336 *
337 * Freemius filters collection:
338 *
339 * fs_connect_url_{plugin_slug}
340 * fs_trial_promotion_message_{plugin_slug}
341 * fs_is_long_term_user_{plugin_slug}
342 * fs_uninstall_reasons_{plugin_slug}
343 * fs_is_plugin_update_{plugin_slug}
344 * fs_api_domains_{plugin_slug}
345 * fs_email_template_sections_{plugin_slug}
346 * fs_support_forum_submenu_{plugin_slug}
347 * fs_support_forum_url_{plugin_slug}
348 * fs_connect_message_{plugin_slug}
349 * fs_connect_message_on_update_{plugin_slug}
350 * fs_uninstall_confirmation_message_{plugin_slug}
351 * fs_pending_activation_message_{plugin_slug}
352 * fs_is_submenu_visible_{plugin_slug}
353 * fs_plugin_icon_{plugin_slug}
354 * fs_show_trial_{plugin_slug}
355 *
356 * --------------------------------------------------------
357 *
358 * Freemius actions collection:
359 *
360 * fs_after_license_loaded_{plugin_slug}
361 * fs_after_license_change_{plugin_slug}
362 * fs_after_plans_sync_{plugin_slug}
363 *
364 * fs_after_account_details_{plugin_slug}
365 * fs_after_account_user_sync_{plugin_slug}
366 * fs_after_account_plan_sync_{plugin_slug}
367 * fs_before_account_load_{plugin_slug}
368 * fs_after_account_connection_{plugin_slug}
369 * fs_account_property_edit_{plugin_slug}
370 * fs_account_email_verified_{plugin_slug}
371 * fs_account_page_load_before_departure_{plugin_slug}
372 * fs_before_account_delete_{plugin_slug}
373 * fs_after_account_delete_{plugin_slug}
374 *
375 * fs_sdk_version_update_{plugin_slug}
376 * fs_plugin_version_update_{plugin_slug}
377 *
378 * fs_initiated_{plugin_slug}
379 * fs_after_init_plugin_registered_{plugin_slug}
380 * fs_after_init_plugin_anonymous_{plugin_slug}
381 * fs_after_init_plugin_pending_activations_{plugin_slug}
382 * fs_after_init_addon_registered_{plugin_slug}
383 * fs_after_init_addon_anonymous_{plugin_slug}
384 * fs_after_init_addon_pending_activations_{plugin_slug}
385 *
386 * fs_after_premium_version_activation_{plugin_slug}
387 * fs_after_free_version_reactivation_{plugin_slug}
388 *
389 * fs_after_uninstall_{plugin_slug}
390 * fs_before_admin_menu_init_{plugin_slug}
391 */
392
393 #endregion Hooks & Filters Collection --------------------------------------------------------------------
394
395 if ( ! class_exists( 'Freemius' ) ) {
396
397 if ( ! defined( 'WP_FS__SDK_VERSION' ) ) {
398 define( 'WP_FS__SDK_VERSION', $this_sdk_version );
399 }
400
401 $plugins_or_theme_dir_path = fs_normalize_path( trailingslashit( $is_theme ?
402 $themes_directory :
403 WP_PLUGIN_DIR ) );
404
405 if ( 0 === strpos( $file_path, $plugins_or_theme_dir_path ) ) {
406 // No symlinks
407 } else {
408 /**
409 * This logic finds the SDK symlink and set WP_FS__DIR to use it.
410 *
411 * @author Vova Feldman (@svovaf)
412 * @since 1.2.2.5
413 */
414 $sdk_symlink = null;
415
416 // Try to load SDK's symlink from cache.
417 if ( isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) &&
418 is_object( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) &&
419 ! empty( $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink )
420 ) {
421 $sdk_symlink = $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink;
422 if ( 0 === strpos( $sdk_symlink, $plugins_or_theme_dir_path ) ) {
423 /**
424 * Make the symlink path relative.
425 *
426 * @author Leo Fajardo (@leorw)
427 */
428 $sdk_symlink = substr( $sdk_symlink, strlen( $plugins_or_theme_dir_path ) );
429
430 $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink = $sdk_symlink;
431 update_option( 'fs_active_plugins', $fs_active_plugins );
432 }
433
434 $realpath = realpath( $plugins_or_theme_dir_path . $sdk_symlink );
435 if ( ! is_string( $realpath ) || ! file_exists( $realpath ) ) {
436 $sdk_symlink = null;
437 }
438 }
439
440 if ( empty( $sdk_symlink ) ) // Has symlinks, therefore, we need to configure WP_FS__DIR based on the symlink.
441 {
442 $partial_path_right = basename( $file_path );
443 $partial_path_left = dirname( $file_path );
444 $realpath = realpath( $plugins_or_theme_dir_path . $partial_path_right );
445
446 while ( '/' !== $partial_path_left &&
447 ( false === $realpath || $file_path !== fs_normalize_path( $realpath ) )
448 ) {
449 $partial_path_right = trailingslashit( basename( $partial_path_left ) ) . $partial_path_right;
450 $partial_path_left_prev = $partial_path_left;
451 $partial_path_left = dirname( $partial_path_left_prev );
452
453 /**
454 * Avoid infinite loop if for example `$partial_path_left_prev` is `C:/`, in this case,
455 * `dirname( 'C:/' )` will return `C:/`.
456 *
457 * @author Leo Fajardo (@leorw)
458 */
459 if ( $partial_path_left === $partial_path_left_prev ) {
460 $partial_path_left = '';
461 break;
462 }
463
464 $realpath = realpath( $plugins_or_theme_dir_path . $partial_path_right );
465 }
466
467 if ( ! empty( $partial_path_left ) && '/' !== $partial_path_left ) {
468 $sdk_symlink = fs_normalize_path( dirname( $partial_path_right ) );
469
470 // Cache value.
471 if ( isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) &&
472 is_object( $fs_active_plugins->plugins[ $this_sdk_relative_path ] )
473 ) {
474 $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink = $sdk_symlink;
475 update_option( 'fs_active_plugins', $fs_active_plugins );
476 }
477 }
478 }
479
480 if ( ! empty( $sdk_symlink ) ) {
481 // Set SDK dir to the symlink path.
482 define( 'WP_FS__DIR', $plugins_or_theme_dir_path . $sdk_symlink );
483 }
484 }
485
486 // Load SDK files.
487 require_once dirname( __FILE__ ) . '/require.php';
488
489 /**
490 * Quick shortcut to get Freemius for specified plugin.
491 * Used by various templates.
492 *
493 * @param number $module_id
494 *
495 * @return Freemius
496 */
497 function freemius( $module_id ) {
498 return Freemius::instance( $module_id );
499 }
500
501 /**
502 * @param string $slug
503 * @param number $plugin_id
504 * @param string $public_key
505 * @param bool $is_live Is live or test plugin.
506 * @param bool $is_premium Hints freemius if running the premium plugin or not.
507 *
508 * @return Freemius
509 *
510 * @deprecated Please use fs_dynamic_init().
511 */
512 function fs_init( $slug, $plugin_id, $public_key, $is_live = true, $is_premium = true ) {
513 $fs = Freemius::instance( $plugin_id, $slug, true );
514 $fs->init( $plugin_id, $public_key, $is_live, $is_premium );
515
516 return $fs;
517 }
518
519 /**
520 * @param array <string,string|bool|array> $module Plugin or Theme details.
521 *
522 * @return Freemius
523 * @throws Freemius_Exception
524 */
525 function fs_dynamic_init( $module ) {
526 $fs = Freemius::instance( $module['id'], $module['slug'], true );
527 $fs->dynamic_init( $module );
528
529 return $fs;
530 }
531
532 function fs_dump_log() {
533 FS_Logger::dump();
534 }
535 }
536