PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 2.0.2
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v2.0.2
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 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.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / freemius / start.php
embedpress / freemius Last commit date
assets 9 years ago includes 9 years ago languages 9 years ago templates 9 years ago LICENSE.txt 9 years ago config.php 9 years ago index.php 9 years ago require.php 9 years ago start.php 9 years ago
start.php
417 lines
1 <?php
2 /**
3 * @package Freemius
4 * @copyright Copyright (c) 2015, Freemius, Inc.
5 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
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.1.7.1';
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 $file_path = fs_normalize_path( __FILE__ );
40 $fs_root_path = dirname( $file_path );
41 $this_sdk_relative_path = plugin_basename( $fs_root_path );
42
43 if ( ! isset( $fs_active_plugins ) ) {
44 if ( ! function_exists( '__fs' ) ) {
45 // Require SDK essentials.
46 require_once dirname( __FILE__ ) . '/includes/fs-essential-functions.php';
47 }
48
49 // Load all Freemius powered active plugins.
50 $fs_active_plugins = get_option( 'fs_active_plugins', new stdClass() );
51
52 if ( ! isset( $fs_active_plugins->plugins ) ) {
53 $fs_active_plugins->plugins = array();
54 }
55 }
56
57 if ( empty( $fs_active_plugins->abspath ) ) {
58 /**
59 * Store the WP install absolute path reference to identify environment change
60 * while replicating the storage.
61 *
62 * @author Vova Feldman (@svovaf)
63 * @since 1.2.1.7
64 */
65 $fs_active_plugins->abspath = ABSPATH;
66 } else {
67 if ( ABSPATH !== $fs_active_plugins->abspath ) {
68 /**
69 * WordPress path has changed, cleanup the SDK references cache.
70 * This resolves issues triggered when spinning a staging environments
71 * while replicating the database.
72 *
73 * @author Vova Feldman (@svovaf)
74 * @since 1.2.1.7
75 */
76 $fs_active_plugins->abspath = ABSPATH;
77 $fs_active_plugins->plugins = array();
78 unset( $fs_active_plugins->newest );
79 } else {
80 /**
81 * Make sure SDK references are still valid. This resolves
82 * issues when users hard delete modules via FTP.
83 *
84 * @author Vova Feldman (@svovaf)
85 * @since 1.2.1.7
86 */
87 foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
88 if ( ! file_exists( WP_PLUGIN_DIR . '/' . $sdk_path ) ) {
89 unset( $fs_active_plugins->plugins[ $sdk_path ] );
90 }
91
92 update_option( 'fs_active_plugins', $fs_active_plugins );
93 }
94 }
95 }
96
97 if ( ! function_exists( 'fs_find_direct_caller_plugin_file' ) ) {
98 require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-1.1.7.1.php';
99 }
100
101 // Update current SDK info based on the SDK path.
102 if ( ! isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) ||
103 $this_sdk_version != $fs_active_plugins->plugins[ $this_sdk_relative_path ]->version
104 ) {
105 $fs_active_plugins->plugins[ $this_sdk_relative_path ] = (object) array(
106 'version' => $this_sdk_version,
107 'timestamp' => time(),
108 'plugin_path' => plugin_basename( fs_find_direct_caller_plugin_file( __FILE__ ) ),
109 );
110 }
111
112 $is_current_sdk_newest = isset( $fs_active_plugins->newest ) && ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path );
113
114 if ( ! isset( $fs_active_plugins->newest ) ) {
115 /**
116 * This will be executed only once, for the first time a Freemius powered plugin is activated.
117 */
118 fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
119
120 $is_current_sdk_newest = true;
121 } else if ( version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '<' ) ) {
122 /**
123 * Current SDK is newer than the newest stored SDK.
124 */
125 fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
126
127 if ( class_exists( 'Freemius' ) ) {
128 // Older SDK version was already loaded.
129
130 if ( ! $fs_active_plugins->newest->in_activation ) {
131 // Re-order plugins to load this plugin first.
132 fs_newest_sdk_plugin_first();
133 }
134
135 // Refresh page.
136 fs_redirect( $_SERVER['REQUEST_URI'] );
137 }
138 } else {
139 if ( ! function_exists( 'get_plugins' ) ) {
140 require_once ABSPATH . 'wp-admin/includes/plugin.php';
141 }
142
143 $is_newest_sdk_plugin_active = is_plugin_active( $fs_active_plugins->newest->plugin_path );
144
145 if ( $is_current_sdk_newest &&
146 ! $is_newest_sdk_plugin_active &&
147 ! $fs_active_plugins->newest->in_activation
148 ) {
149 // If current SDK is the newest and the plugin is NOT active, it means
150 // that the current plugin in activation mode.
151 $fs_active_plugins->newest->in_activation = true;
152 update_option( 'fs_active_plugins', $fs_active_plugins );
153 }
154
155 $is_newest_sdk_path_valid = ( $is_newest_sdk_plugin_active || $fs_active_plugins->newest->in_activation ) && file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this_sdk_relative_path . '/start.php' ) );
156
157 if ( ! $is_newest_sdk_path_valid && ! $is_current_sdk_newest ) {
158 // Plugin with newest SDK is no longer active, or SDK was moved to a different location.
159 unset( $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ] );
160 }
161
162 if ( ! ( $is_newest_sdk_plugin_active || $fs_active_plugins->newest->in_activation ) ||
163 ! $is_newest_sdk_path_valid ||
164 // Is newest SDK downgraded.
165 ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
166 version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '>' ) )
167 ) {
168 /**
169 * Plugin with newest SDK is no longer active.
170 * OR
171 * The newest SDK was in the current plugin. BUT, seems like the version of
172 * the SDK was downgraded to a lower SDK.
173 */
174 // Find the active plugin with the newest SDK version and update the newest reference.
175 fs_fallback_to_newest_active_sdk();
176 } else {
177 if ( $is_newest_sdk_plugin_active &&
178 $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
179 ( $fs_active_plugins->newest->in_activation ||
180 ( class_exists( 'Freemius' ) && ( ! defined( 'WP_FS__SDK_VERSION' ) || version_compare( WP_FS__SDK_VERSION, $this_sdk_version, '<' ) ) )
181 )
182
183 ) {
184 if ( $fs_active_plugins->newest->in_activation ) {
185 // Plugin no more in activation.
186 $fs_active_plugins->newest->in_activation = false;
187 update_option( 'fs_active_plugins', $fs_active_plugins );
188 }
189
190 // Reorder plugins to load plugin with newest SDK first.
191 if ( fs_newest_sdk_plugin_first() ) {
192 // Refresh page after re-order to make sure activated plugin loads newest SDK.
193 if ( class_exists( 'Freemius' ) ) {
194 fs_redirect( $_SERVER['REQUEST_URI'] );
195 }
196 }
197 }
198 }
199 }
200
201 if ( class_exists( 'Freemius' ) ) {
202 // SDK was already loaded.
203 return;
204 }
205
206 if ( version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) {
207 $newest_sdk_starter = fs_normalize_path( WP_PLUGIN_DIR . '/' . $fs_active_plugins->newest->sdk_path . '/start.php' );
208
209 if ( file_exists( $newest_sdk_starter ) ) {
210 // Reorder plugins to load plugin with newest SDK first.
211 fs_newest_sdk_plugin_first();
212
213 // There's a newer SDK version, load it instead of the current one!
214 require_once $newest_sdk_starter;
215
216 return;
217 }
218 }
219
220 #endregion SDK Selection Logic --------------------------------------------------------------------
221
222 #region Hooks & Filters Collection --------------------------------------------------------------------
223
224 /**
225 * Freemius hooks (actions & filters) tags structure:
226 *
227 * fs_{filter/action_name}_{plugin_slug}
228 *
229 * --------------------------------------------------------
230 *
231 * Usage with WordPress' add_action() / add_filter():
232 *
233 * add_action('fs_{filter/action_name}_{plugin_slug}', $callable);
234 *
235 * --------------------------------------------------------
236 *
237 * Usage with Freemius' instance add_action() / add_filter():
238 *
239 * // No need to add 'fs_' prefix nor '_{plugin_slug}' suffix.
240 * my_freemius()->add_action('{action_name}', $callable);
241 *
242 * --------------------------------------------------------
243 *
244 * Freemius filters collection:
245 *
246 * fs_connect_url_{plugin_slug}
247 * fs_trial_promotion_message_{plugin_slug}
248 * fs_is_long_term_user_{plugin_slug}
249 * fs_uninstall_reasons_{plugin_slug}
250 * fs_is_plugin_update_{plugin_slug}
251 * fs_api_domains_{plugin_slug}
252 * fs_email_template_sections_{plugin_slug}
253 * fs_support_forum_submenu_{plugin_slug}
254 * fs_support_forum_url_{plugin_slug}
255 * fs_connect_message_{plugin_slug}
256 * fs_connect_message_on_update_{plugin_slug}
257 * fs_uninstall_confirmation_message_{plugin_slug}
258 * fs_pending_activation_message_{plugin_slug}
259 * fs_is_submenu_visible_{plugin_slug}
260 * fs_plugin_icon_{plugin_slug}
261 * fs_show_trial_{plugin_slug}
262 *
263 * --------------------------------------------------------
264 *
265 * Freemius actions collection:
266 *
267 * fs_after_license_loaded_{plugin_slug}
268 * fs_after_license_change_{plugin_slug}
269 * fs_after_plans_sync_{plugin_slug}
270 *
271 * fs_after_account_details_{plugin_slug}
272 * fs_after_account_user_sync_{plugin_slug}
273 * fs_after_account_plan_sync_{plugin_slug}
274 * fs_before_account_load_{plugin_slug}
275 * fs_after_account_connection_{plugin_slug}
276 * fs_account_property_edit_{plugin_slug}
277 * fs_account_email_verified_{plugin_slug}
278 * fs_account_page_load_before_departure_{plugin_slug}
279 * fs_before_account_delete_{plugin_slug}
280 * fs_after_account_delete_{plugin_slug}
281 *
282 * fs_sdk_version_update_{plugin_slug}
283 * fs_plugin_version_update_{plugin_slug}
284 *
285 * fs_initiated_{plugin_slug}
286 * fs_after_init_plugin_registered_{plugin_slug}
287 * fs_after_init_plugin_anonymous_{plugin_slug}
288 * fs_after_init_plugin_pending_activations_{plugin_slug}
289 * fs_after_init_addon_registered_{plugin_slug}
290 * fs_after_init_addon_anonymous_{plugin_slug}
291 * fs_after_init_addon_pending_activations_{plugin_slug}
292 *
293 * fs_after_premium_version_activation_{plugin_slug}
294 * fs_after_free_version_reactivation_{plugin_slug}
295 *
296 * fs_after_uninstall_{plugin_slug}
297 * fs_before_admin_menu_init_{plugin_slug}
298 */
299
300 #endregion Hooks & Filters Collection --------------------------------------------------------------------
301
302 if ( ! class_exists( 'Freemius' ) ) {
303
304 if ( ! defined( 'WP_FS__SDK_VERSION' ) ) {
305 define( 'WP_FS__SDK_VERSION', $this_sdk_version );
306 }
307
308 $plugins_or_theme_dir_path = WP_PLUGIN_DIR;
309
310 if ( 0 === strpos( $file_path, fs_normalize_path( $plugins_or_theme_dir_path ) ) ) {
311 // No symlinks
312 } else {
313 /**
314 * This logic finds the SDK symlink and set WP_FS__DIR to use it.
315 *
316 * @author Vova Feldman (@svovaf)
317 * @since 1.2.2.5
318 */
319 $sdk_symlink = null;
320
321 // Try to load SDK's symlink from cache.
322 if ( isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) &&
323 is_object( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) &&
324 ! empty( $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink )
325 ) {
326 $sdk_symlink = $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink;
327 $realpath = realpath( $sdk_symlink );
328
329 if ( ! is_string( $realpath ) || ! file_exists( $realpath ) ) {
330 $sdk_symlink = null;
331 }
332 }
333
334 if ( empty( $sdk_symlink ) ) // Has symlinks, therefore, we need to configure WP_FS__DIR based on the symlink.
335 {
336 $partial_path_right = basename( $file_path );
337 $partial_path_left = dirname( $file_path );
338 $realpath = realpath( $plugins_or_theme_dir_path . $partial_path_right );
339
340 while ( '/' !== $partial_path_left &&
341 ( false === $realpath || $file_path !== fs_normalize_path( $realpath ) )
342 ) {
343 $partial_path_right = trailingslashit( basename( $partial_path_left ) ) . $partial_path_right;
344 $partial_path_left = dirname( $partial_path_left );
345 $realpath = realpath( $plugins_or_theme_dir_path . $partial_path_right );
346 }
347
348 if ( '/' !== $partial_path_left ) {
349 $sdk_symlink = fs_normalize_path( $plugins_or_theme_dir_path . dirname( $partial_path_right ) );
350
351 // Cache value.
352 if ( isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) &&
353 is_object( $fs_active_plugins->plugins[ $this_sdk_relative_path ] )
354 ) {
355 $fs_active_plugins->plugins[ $this_sdk_relative_path ]->sdk_symlink = $sdk_symlink;
356 update_option( 'fs_active_plugins', $fs_active_plugins );
357 }
358
359 }
360 }
361
362 if ( ! empty( $sdk_symlink ) ) {
363 // Set SDK dir to the symlink path.
364 define( 'WP_FS__DIR', $sdk_symlink );
365 }
366 }
367
368 // Load SDK files.
369 require_once dirname( __FILE__ ) . '/require.php';
370
371 /**
372 * Quick shortcut to get Freemius for specified plugin.
373 * Used by various templates.
374 *
375 * @param string $slug
376 *
377 * @return Freemius
378 */
379 function freemius( $slug ) {
380 return Freemius::instance( $slug );
381 }
382
383 /**
384 * @param string $slug
385 * @param number $plugin_id
386 * @param string $public_key
387 * @param bool $is_live Is live or test plugin.
388 * @param bool $is_premium Hints freemius if running the premium plugin or not.
389 *
390 * @return Freemius
391 *
392 * @deprecated Please use fs_dynamic_init().
393 */
394 function fs_init( $slug, $plugin_id, $public_key, $is_live = true, $is_premium = true ) {
395 $fs = Freemius::instance( $slug, true );
396 $fs->init( $plugin_id, $public_key, $is_live, $is_premium );
397
398 return $fs;
399 }
400
401 /**
402 * @param array <string,string> $module Plugin or Theme details.
403 *
404 * @return Freemius
405 * @throws Freemius_Exception
406 */
407 function fs_dynamic_init( $module ) {
408 $fs = Freemius::instance( $module['slug'], true );
409 $fs->dynamic_init( $module );
410
411 return $fs;
412 }
413
414 function fs_dump_log() {
415 FS_Logger::dump();
416 }
417 }