namespace Google\Site_Kit_Dependencies\React\Promise; /** * Creates a promise for the supplied `$promiseOrValue`. * * If `$promiseOrValue` is a value, it will be the resolution value of the * returned promise. * * If `$promiseOrValue` is a thenable (any object that provides a `then()` method), * a trusted promise that follows the state of the thenable is returned. * * If `$promiseOrValue` is a promise, it will be returned as is. * * @param mixed $promiseOrValue * @return PromiseInterface */ function resolve($promiseOrValue = null) { if ($promiseOrValue instanceof \Google\Site_Kit_Dependencies\React\Promise\ExtendedPromiseInterface) { return $promiseOrValue; } // Check is_object() first to avoid method_exists() triggering // class autoloaders if $promiseOrValue is a string. if (\is_object($promiseOrValue) && \method_exists($promiseOrValue, 'then')) { $canceller = null; if (\method_exists($promiseOrValue, 'cancel')) { $canceller = [$promiseOrValue, 'cancel']; } return new \Google\Site_Kit_Dependencies\React\Promise\Promise(function ($resolve, $reject, $notify) use($promiseOrValue) { $promiseOrValue->then($resolve, $reject, $notify); }, $canceller); } return new \Google\Site_Kit_Dependencies\React\Promise\FulfilledPromise($promiseOrValue); } /** * Creates a rejected promise for the supplied `$promiseOrValue`. * * If `$promiseOrValue` is a value, it will be the rejection value of the * returned promise. * * If `$promiseOrValue` is a promise, its completion value will be the rejected * value of the returned promise. * * This can be useful in situations where you need to reject a promise without * throwing an exception. For example, it allows you to propagate a rejection with * the value of another promise. * * @param mixed $promiseOrValue * @return PromiseInterface */ function reject($promiseOrValue = null) { if ($promiseOrValue instanceof \Google\Site_Kit_Dependencies\React\Promise\PromiseInterface) { return resolve($promiseOrValue)->then(function ($value) { return new \Google\Site_Kit_Dependencies\React\Promise\RejectedPromise($value); }); } return new \Google\Site_Kit_Dependencies\React\Promise\RejectedPromise($promiseOrValue); } /** * Returns a promise that will resolve only once all the items in * `$promisesOrValues` have resolved. The resolution value of the returned promise * will be an array containing the resolution values of each of the items in * `$promisesOrValues`. * * @param array $promisesOrValues * @return PromiseInterface */ function all($promisesOrValues) { return map($promisesOrValues, function ($val) { return $val; }); } /** * Initiates a competitive race that allows one winner. Returns a promise which is * resolved in the same way the first settled promise resolves. * * The returned promise will become **infinitely pending** if `$promisesOrValues` * contains 0 items. * * @param array $promisesOrValues * @return PromiseInterface */ function race($promisesOrValues) { $cancellationQueue = new \Google\Site_Kit_Dependencies\React\Promise\CancellationQueue(); $cancellationQueue->enqueue($promisesOrValues); return new \Google\Site_Kit_Dependencies\React\Promise\Promise(function ($resolve, $reject, $notify) use($promisesOrValues, $cancellationQueue) { resolve($promisesOrValues)->done(function ($array) use($cancellationQueue, $resolve, $reject, $notify) { if (!\is_array($array) || !$array) { $resolve(); return; } foreach ($array as $promiseOrValue) { $cancellationQueue->enqueue($promiseOrValue); resolve($promiseOrValue)->done($resolve, $reject, $notify); } }, $reject, $notify); }, $cancellationQueue); } /** * Returns a promise that will resolve when any one of the items in * `$promisesOrValues` resolves. The resolution value of the returned promise * will be the resolution value of the triggering item. * * The returned promise will only reject if *all* items in `$promisesOrValues` are * rejected. The rejection value will be an array of all rejection reasons. * * The returned promise will also reject with a `React\Promise\Exception\LengthException` * if `$promisesOrValues` contains 0 items. * * @param array $promisesOrValues * @return PromiseInterface */ function any($promisesOrValues) { return some($promisesOrValues, 1)->then(function ($val) { return \array_shift($val); }); } /** * Returns a promise that will resolve when `$howMany` of the supplied items in * `$promisesOrValues` resolve. The resolution value of the returned promise * will be an array of length `$howMany` containing the resolution values of the * triggering items. * * The returned promise will reject if it becomes impossible for `$howMany` items * to resolve (that is, when `(count($promisesOrValues) - $howMany) + 1` items * reject). The rejection value will be an array of * `(count($promisesOrValues) - $howMany) + 1` rejection reasons. * * The returned promise will also reject with a `React\Promise\Exception\LengthException` * if `$promisesOrValues` contains less items than `$howMany`. * * @param array $promisesOrValues * @param int $howMany * @return PromiseInterface */ function some($promisesOrValues, $howMany) { $cancellationQueue = new \Google\Site_Kit_Dependencies\React\Promise\CancellationQueue(); $cancellationQueue->enqueue($promisesOrValues); return new \Google\Site_Kit_Dependencies\React\Promise\Promise(function ($resolve, $reject, $notify) use($promisesOrValues, $howMany, $cancellationQueue) { resolve($promisesOrValues)->done(function ($array) use($howMany, $cancellationQueue, $resolve, $reject, $notify) { if (!\is_array($array) || $howMany < 1) { $resolve([]); return; } $len = \count($array); if ($len < $howMany) { throw new \Google\Site_Kit_Dependencies\React\Promise\Exception\LengthException(\sprintf('Input array must contain at least %d item%s but contains only %s item%s.', $howMany, 1 === $howMany ? '' : 's', $len, 1 === $len ? '' : 's')); } $toResolve = $howMany; $toReject = $len - $toResolve + 1; $values = []; $reasons = []; foreach ($array as $i => $promiseOrValue) { $fulfiller = function ($val) use($i, &$values, &$toResolve, $toReject, $resolve) { if ($toResolve < 1 || $toReject < 1) { return; } $values[$i] = $val; if (0 === --$toResolve) { $resolve($values); } }; $rejecter = function ($reason) use($i, &$reasons, &$toReject, $toResolve, $reject) { if ($toResolve < 1 || $toReject < 1) { return; } $reasons[$i] = $reason; if (0 === --$toReject) { $reject($reasons); } }; $cancellationQueue->enqueue($promiseOrValue); resolve($promiseOrValue)->done($fulfiller, $rejecter, $notify); } }, $reject, $notify); }, $cancellationQueue); } /** * Traditional map function, similar to `array_map()`, but allows input to contain * promises and/or values, and `$mapFunc` may return either a value or a promise. * * The map function receives each item as argument, where item is a fully resolved * value of a promise or value in `$promisesOrValues`. * * @param array $promisesOrValues * @param callable $mapFunc * @return PromiseInterface */ function map($promisesOrValues, callable $mapFunc) { $cancellationQueue = new \Google\Site_Kit_Dependencies\React\Promise\CancellationQueue(); $cancellationQueue->enqueue($promisesOrValues); return new \Google\Site_Kit_Dependencies\React\Promise\Promise(function ($resolve, $reject, $notify) use($promisesOrValues, $mapFunc, $cancellationQueue) { resolve($promisesOrValues)->done(function ($array) use($mapFunc, $cancellationQueue, $resolve, $reject, $notify) { if (!\is_array($array) || !$array) { $resolve([]); return; } $toResolve = \count($array); $values = []; foreach ($array as $i => $promiseOrValue) { $cancellationQueue->enqueue($promiseOrValue); $values[$i] = null; resolve($promiseOrValue)->then($mapFunc)->done(function ($mapped) use($i, &$values, &$toResolve, $resolve) { $values[$i] = $mapped; if (0 === --$toResolve) { $resolve($values); } }, $reject, $notify); } }, $reject, $notify); }, $cancellationQueue); } /** * Traditional reduce function, similar to `array_reduce()`, but input may contain * promises and/or values, and `$reduceFunc` may return either a value or a * promise, *and* `$initialValue` may be a promise or a value for the starting * value. * * @param array $promisesOrValues * @param callable $reduceFunc * @param mixed $initialValue * @return PromiseInterface */ function reduce($promisesOrValues, callable $reduceFunc, $initialValue = null) { $cancellationQueue = new \Google\Site_Kit_Dependencies\React\Promise\CancellationQueue(); $cancellationQueue->enqueue($promisesOrValues); return new \Google\Site_Kit_Dependencies\React\Promise\Promise(function ($resolve, $reject, $notify) use($promisesOrValues, $reduceFunc, $initialValue, $cancellationQueue) { resolve($promisesOrValues)->done(function ($array) use($reduceFunc, $initialValue, $cancellationQueue, $resolve, $reject, $notify) { if (!\is_array($array)) { $array = []; } $total = \count($array); $i = 0; // Wrap the supplied $reduceFunc with one that handles promises and then // delegates to the supplied. $wrappedReduceFunc = function ($current, $val) use($reduceFunc, $cancellationQueue, $total, &$i) { $cancellationQueue->enqueue($val); return $current->then(function ($c) use($reduceFunc, $total, &$i, $val) { return resolve($val)->then(function ($value) use($reduceFunc, $total, &$i, $c) { return $reduceFunc($c, $value, $i++, $total); }); }); }; $cancellationQueue->enqueue($initialValue); \array_reduce($array, $wrappedReduceFunc, resolve($initialValue))->done($resolve, $reject, $notify); }, $reject, $notify); }, $cancellationQueue); } /** * @internal */ function _checkTypehint(callable $callback, $object) { if (!\is_object($object)) { return \true; } if (\is_array($callback)) { $callbackReflection = new \ReflectionMethod($callback[0], $callback[1]); } elseif (\is_object($callback) && !$callback instanceof \Closure) { $callbackReflection = new \ReflectionMethod($callback, '__invoke'); } else { $callbackReflection = new \ReflectionFunction($callback); } $parameters = $callbackReflection->getParameters(); if (!isset($parameters[0])) { return \true; } $expectedException = $parameters[0]; // PHP before v8 used an easy API: if (\PHP_VERSION_ID < 70100 || \defined('Google\\Site_Kit_Dependencies\\HHVM_VERSION')) { if (!$expectedException->getClass()) { return \true; } return $expectedException->getClass()->isInstance($object); } // Extract the type of the argument and handle different possibilities $type = $expectedException->getType(); $isTypeUnion = \true; $types = []; switch (\true) { case $type === null: break; case $type instanceof \ReflectionNamedType: $types = [$type]; break; case $type instanceof \Google\Site_Kit_Dependencies\ReflectionIntersectionType: $isTypeUnion = \false; case $type instanceof \ReflectionUnionType: $types = $type->getTypes(); break; default: throw new \LogicException('Unexpected return value of ReflectionParameter::getType'); } // If there is no type restriction, it matches if (empty($types)) { return \true; } foreach ($types as $type) { if (!$type instanceof \ReflectionNamedType) { throw new \LogicException('This implementation does not support groups of intersection or union types'); } // A named-type can be either a class-name or a built-in type like string, int, array, etc. $matches = $type->isBuiltin() && \gettype($object) === $type->getName() || (new \ReflectionClass($type->getName()))->isInstance($object); // If we look for a single match (union), we can return early on match // If we look for a full match (intersection), we can return early on mismatch if ($matches) { if ($isTypeUnion) { return \true; } } else { if (!$isTypeUnion) { return \false; } } } // If we look for a single match (union) and did not return early, we matched no type and are false // If we look for a full match (intersection) and did not return early, we matched all types and are true return $isTypeUnion ? \false : \true; } /** * Get path to wp-config.php when called from WP-CLI. * * @return string */ function wpo_wp_cli_locate_wp_config() { $config_path = ''; if (is_callable('\WP_CLI\Utils\locate_wp_config')) { // phpcs:ignore PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ns_separatorFound $config_path = \WP_CLI\Utils\locate_wp_config(); } return $config_path; } if (!defined('ABSPATH')) die('No direct access allowed'); if (!defined('WP_OPTIMIZE_MINIFY_DIR')) { die('No direct access.'); } if (!function_exists('wpo_delete_files')) { include WPO_PLUGIN_MAIN_PATH.'cache/file-based-page-cache-functions.php'; } class WP_Optimize_Minify_Cache_Functions { /** * Fix the permission bits on generated files * * @param String $file - full path to a file */ public static function fix_permission_bits($file) { if (function_exists('stat')) { if ($stat = stat(dirname($file))) { $perms = $stat['mode'] & 0007777; chmod($file, $perms); clearstatcache(); return true; } } // Get permissions from parent directory $perms = 0777; if (function_exists('stat')) { if ($stat = stat(dirname($file))) { $perms = $stat['mode'] & 0007777; } } if (file_exists($file)) { if (($perms & ~umask() != $perms)) { $folder_parts = explode('/', substr($file, strlen(dirname($file)) + 1)); for ($i = 1, $c = count($folder_parts); $i <= $c; $i++) { chmod(dirname($file) . '/' . implode('/', array_slice($folder_parts, 0, $i)), $perms); } } } return true; } /** * Get cache directories and urls * * @return Array */ public static function cache_path() { // get latest time stamp $cache_time = wp_optimize_minify_config()->get('last-cache-update'); $cache_dir_url = WPO_CACHE_MIN_FILES_URL . "/$cache_time/assets"; $tmp_dir = WPO_CACHE_MIN_FILES_DIR . "/tmp"; $header_dir = WPO_CACHE_MIN_FILES_DIR . "/$cache_time/header"; $cache_dir = WPO_CACHE_MIN_FILES_DIR . "/$cache_time/assets"; // Create directories $dirs = array($cache_dir, $tmp_dir, $header_dir); foreach ($dirs as $target) { $enabled = wp_optimize_minify_config()->get('enabled'); if (false === $enabled) break; if (!is_dir($target) && !wp_mkdir_p($target)) { error_log('WP_Optimize_Minify_Cache_Functions::cache_path(): The folder "'.$target.'" could not be created.'); } } return array( 'tmpdir' => $tmp_dir, 'cachedir' => $cache_dir, 'cachedirurl' => $cache_dir_url, 'headerdir' => $header_dir ); } /** * Increment file names */ public static function cache_increment() { $stamp = time(); wp_optimize_minify_config()->update(array( 'last-cache-update' => $stamp )); return $stamp; } /** * Reset the cache (Increment + purge temp files) */ public static function reset() { self::cache_increment(); self::purge_temp_files(); } /** * Will delete temporary intermediate stuff but leave final css/js alone for compatibility * * @return Array */ public static function purge_temp_files() { // get cache directories and urls $cache_path = self::cache_path(); $tmp_dir = $cache_path['tmpdir']; $header_dir = $cache_path['headerdir']; // delete temporary directories only if (is_dir($tmp_dir)) { wpo_delete_files($tmp_dir, true); } if (is_dir($header_dir)) { wpo_delete_files($header_dir, true); } /** * Action triggered after purging temporary files */ do_action('wpo_min_after_purge_temp_files'); return array( 'tmpdir' => $tmp_dir, 'headerdir' => $header_dir, ); } /** * Purge supported hosting and plugins * * @return string */ public static function purge_others() { /** * Action triggered before purging other plugins cache */ do_action('wpo_min_before_purge_others'); // WordPress default cache if (function_exists('wp_cache_flush')) { wp_cache_flush(); } // Purge WP-Optimize WP_Optimize()->get_page_cache()->purge(); // When plugins have a simple method, add them to the array ('Plugin Name' => 'method_name') $others = array( 'WP Super Cache' => 'wp_cache_clear_cache', 'W3 Total Cache' => 'w3tc_pgcache_flush', 'WP Fastest Cache' => 'wpfc_clear_all_cache', 'WP Rocket' => 'rocket_clean_domain', 'Cachify' => 'cachify_flush_cache', 'Comet Cache' => array('comet_cache', 'clear'), 'SG Optimizer' => 'sg_cachepress_purge_cache', 'Pantheon' => 'pantheon_wp_clear_edge_all', 'Zen Cache' => array('zencache', 'clear'), 'Breeze' => array('Breeze_PurgeCache', 'breeze_cache_flush'), 'Swift Performance' => array('Swift_Performance_Cache', 'clear_all_cache'), ); foreach ($others as $plugin => $method) { if (is_callable($method)) { call_user_func($method); return sprintf(__('All caches from %s have also been purged.', 'wp-optimize'), ''.$plugin.''); } } // Purge LiteSpeed Cache if (is_callable(array('LiteSpeed_Cache_Tags', 'add_purge_tag'))) { LiteSpeed_Cache_Tags::add_purge_tag('*'); return sprintf(__('All caches from %s have also been purged.', 'wp-optimize'), 'LiteSpeed Cache'); } // Purge Hyper Cache if (class_exists('HyperCache')) { do_action('autoptimize_action_cachepurged'); return sprintf(__('All caches from %s have also been purged.', 'wp-optimize'), 'Hyper Cache'); } // Purge Godaddy Managed WordPress Hosting (Varnish + APC) if (class_exists('WPaaS\Plugin')) { self::godaddy_request('BAN'); return sprintf(__('A cache purge request has been sent to %s. Please note that it may not work every time, due to cache rate limiting by your host.', 'wp-optimize'), 'Go Daddy Varnish'); } // purge cache enabler if (has_action('ce_clear_cache')) { do_action('ce_clear_cache'); return sprintf(__('All caches from %s have also been purged.', 'wp-optimize'), 'Cache Enabler'); } // Purge WP Engine if (class_exists("WpeCommon")) { if (method_exists('WpeCommon', 'purge_memcached')) { WpeCommon::purge_memcached(); } if (method_exists('WpeCommon', 'clear_maxcdn_cache')) { WpeCommon::clear_maxcdn_cache(); } if (method_exists('WpeCommon', 'purge_varnish_cache')) { WpeCommon::purge_varnish_cache(); } if (method_exists('WpeCommon', 'purge_memcached') || method_exists('WpeCommon', 'clear_maxcdn_cache') || method_exists('WpeCommon', 'purge_varnish_cache')) { return sprintf(__('A cache purge request has been sent to %s. Please note that it may not work every time, due to cache rate limiting by your host.', 'wp-optimize'), 'WP Engine'); } } // Purge Kinsta global $kinsta_cache; if (isset($kinsta_cache) && class_exists('\\Kinsta\\CDN_Enabler')) { if (!empty($kinsta_cache->kinsta_cache_purge) && is_callable(array($kinsta_cache->kinsta_cache_purge, 'purge_complete_caches'))) { $kinsta_cache->kinsta_cache_purge->purge_complete_caches(); return sprintf(__('A cache purge request was also sent to %s', 'wp-optimize'), 'Kinsta'); } } // Purge Pagely if (class_exists('PagelyCachePurge')) { $purge_pagely = new PagelyCachePurge(); if (is_callable(array($purge_pagely, 'purgeAll'))) { $purge_pagely->purgeAll(); return sprintf(__('A cache purge request was also sent to %s', 'wp-optimize'), 'Pagely'); } } // Purge Pressidum if (defined('WP_NINUKIS_WP_NAME') && class_exists('Ninukis_Plugin') && is_callable(array('Ninukis_Plugin', 'get_instance'))) { $purge_pressidum = Ninukis_Plugin::get_instance(); if (is_callable(array($purge_pressidum, 'purgeAllCaches'))) { $purge_pressidum->purgeAllCaches(); return sprintf(__('A cache purge request was also sent to %s', 'wp-optimize'), 'Pressidium'); } } // Purge Savvii if (defined('\Savvii\CacheFlusherPlugin::NAME_DOMAINFLUSH_NOW')) { $purge_savvii = new \Savvii\CacheFlusherPlugin(); // phpcs:ignore PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ns_separatorFound if (is_callable(array($purge_savvii, 'domainflush'))) { $purge_savvii->domainflush(); return sprintf(__('A cache purge request was also sent to %s', 'wp-optimize'), 'Savvii'); } } /** * Action triggered when purging other plugins cache, and nothing was triggered */ do_action('wpo_min_after_purge_others'); } /** * Purge all public files on uninstallation * This will break cached pages that ref minified JS/CSS * * @return Boolean */ public static function purge() { $log = ''; if (is_dir(WPO_CACHE_MIN_FILES_DIR)) { if (wpo_delete_files(WPO_CACHE_MIN_FILES_DIR, true)) { $log = "[Minify] files and folders are deleted recursively"; } else { $log = "[Minify] recursive files and folders deletion unsuccessful"; } if (wp_optimize_minify_config()->get('debug')) { error_log($log); } } return true; } /** * Purge cache files older than 30 days * * @return array */ public static function purge_old() { if (!class_exists('WP_Optimize_Minify_Config')) { include_once WPO_PLUGIN_MAIN_PATH . '/minify/class-wp-optimize-minify-config.php'; } $cache_time = wp_optimize_minify_config()->get('last-cache-update'); $cache_lifespan = wp_optimize_minify_config()->get('cache_lifespan'); /** * Minify cache lifespan * * @param int The minify cache expiry timestamp */ $expires = apply_filters('wp_optimize_minify_cache_expiry_time', time() - 86400 * $cache_lifespan); $log = array(); // get all directories that are a direct child of current directory if (is_dir(WPO_CACHE_MIN_FILES_DIR) && is_writable(dirname(WPO_CACHE_MIN_FILES_DIR))) { if ($handle = opendir(WPO_CACHE_MIN_FILES_DIR)) { while (false !== ($d = readdir($handle))) { if (strcmp($d, '.')==0 || strcmp($d, '..')==0) { continue; } $log[] = "cache expiration time - $expires"; $log[] = "checking if cache has expired - $d"; if ($d != $cache_time && (is_numeric($d) && $d <= $expires)) { $dir = WPO_CACHE_MIN_FILES_DIR.'/'.$d; if (is_dir($dir)) { $log[] = "deleting cache in $dir"; if (wpo_delete_files($dir, true)) { $log[] = "files and folders are deleted recursively - $dir"; } else { $log[] = "recursive files and folders deletion unsuccessful - $dir"; } if (file_exists($dir)) { if (rmdir($dir)) { $log[] = "folder deleted successfully - $dir"; } else { $log[] = "folder deletion unsuccessful - $dir"; } } } } } closedir($handle); } } if (wp_optimize_minify_config()->get('debug')) { foreach ($log as $message) { error_log($message); } } return $log; } /** * Get transients from the disk * * @return String|Boolean */ public static function get_transient($key) { $cache_path = self::cache_path(); $tmp_dir = $cache_path['tmpdir']; $f = $tmp_dir.'/'.$key.'.transient'; clearstatcache(); if (file_exists($f)) { return file_get_contents($f); } else { return false; } } /** * Set cache on disk * * @param String $key * @param Mixed $code * * @return Boolean */ public static function set_transient($key, $code) { if (is_null($code) || empty($code)) { return false; } $cache_path = self::cache_path(); $tmp_dir = $cache_path['tmpdir']; $f = $tmp_dir.'/'.$key.'.transient'; file_put_contents($f, $code); self::fix_permission_bits($f); return true; } /** * Get the cache size and count * * @param string $folder * @return String */ public static function get_cachestats($folder) { clearstatcache(); if (is_dir($folder)) { $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder, FilesystemIterator::SKIP_DOTS)); $size = 0; $file_count = 0; foreach ($dir as $file) { $size += $file->getSize(); $file_count++; } return WP_Optimize()->format_size($size) . ' ('.$file_count.' files)'; } else { return sprintf(__('Error: %s is not a directory!', 'wp-optimize'), $folder); } } /** * Purge GoDaddy Managed WordPress Hosting (Varnish) * * Source: https://github.com/wp-media/wp-rocket/blob/master/inc/3rd-party/hosting/godaddy.php * * @param String $method * @param String|Null $url */ public static function godaddy_request($method, $url = null) { $url = empty($url) ? home_url() : $url; $host = parse_url($url, PHP_URL_HOST); $url = set_url_scheme(str_replace($host, WPaas\Plugin::vip(), $url), 'http'); // phpcs:ignore PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ns_separatorFound wp_cache_flush(); update_option('gd_system_last_cache_flush', time()); // purge apc wp_remote_request(esc_url_raw($url), array('method' => $method, 'blocking' => false, 'headers' => array('Host' => $host))); } /** * List all cache files * * @param integer $stamp A timestamp * @param boolean $use_cache If true, do not use transient value * @return array */ public static function get_cached_files($stamp = 0, $use_cache = true) { if ($use_cache && $files = get_transient('wpo_minify_get_cached_files')) { return $files; } $cache_path = self::cache_path(); $cache_dir = $cache_path['cachedir']; $size = self::get_cachestats($cache_dir); $total_size = self::get_cachestats(WPO_CACHE_MIN_FILES_DIR); $o = wp_optimize_minify_config()->get(); $cache_time = (0 == $o['last-cache-update']) ? __('Never.', 'wp-optimize') : self::format_date_time($o['last-cache-update']); $return = array( 'js' => array(), 'css' => array(), 'stamp' => $stamp, 'cachesize' => esc_html($size), 'total_cache_size' => esc_html($total_size), 'cacheTime' => $cache_time, 'cachePath' => $cache_path['cachedir'] ); // Inspect directory with opendir, since glob might not be available in some systems clearstatcache(); if (is_dir($cache_dir.'/') && $handle = opendir($cache_dir.'/')) { while (false !== ($file = readdir($handle))) { $file = $cache_dir.'/'.$file; $ext = pathinfo($file, PATHINFO_EXTENSION); if (in_array($ext, array('js', 'css'))) { $log = false; if (file_exists($file.'.json')) { $log = json_decode(file_get_contents($file.'.json')); } $min_css = substr($file, 0, -4).'.min.css'; $minjs = substr($file, 0, -3).'.min.js'; $file_name = basename($file); $file_url = trailingslashit($cache_path['cachedirurl']).$file_name; if ('css' == $ext && file_exists($min_css)) { $file_name = basename($min_css); } if ('js' == $ext && file_exists($minjs)) { $file_name = basename($minjs); } $file_size = WP_Optimize()->format_size(filesize($file)); $uid = hash('adler32', $file_name); array_push($return[$ext], array('uid' => $uid, 'filename' => $file_name, 'file_url' => $file_url, 'log' => $log, 'fsize' => $file_size)); } } closedir($handle); } set_transient('wpo_minify_get_cached_files', $return, DAY_IN_SECONDS); return $return; } /** * Format a timestamp using WP's date_format and time_format * * @param integer $timestamp - The timestamp * @return string */ public static function format_date_time($timestamp) { return WP_Optimize()->format_date_time($timestamp); } /** * Format the log created when merging assets. Called via array_map * * @param array $files The files array, containing the 'log' object or array. * @return array */ public static function format_file_logs($files) { $files['log'] = WP_Optimize()->include_template( 'minify/cached-file-log.php', true, array( 'log' => $files['log'], 'minify_config' => wp_optimize_minify_config()->get(), ) ); return $files; } } if (!defined('ABSPATH')) die('No direct access allowed'); if (!defined('WP_OPTIMIZE_MINIFY_DIR')) { die('No direct access.'); } if (!function_exists('wpo_delete_files')) { include WPO_PLUGIN_MAIN_PATH.'cache/file-based-page-cache-functions.php'; } class WP_Optimize_Minify_Cache_Functions { /** * Fix the permission bits on generated files * * @param String $file - full path to a file */ public static function fix_permission_bits($file) { if (function_exists('stat')) { if ($stat = stat(dirname($file))) { $perms = $stat['mode'] & 0007777; chmod($file, $perms); clearstatcache(); return true; } } // Get permissions from parent directory $perms = 0777; if (function_exists('stat')) { if ($stat = stat(dirname($file))) { $perms = $stat['mode'] & 0007777; } } if (file_exists($file)) { if (($perms & ~umask() != $perms)) { $folder_parts = explode('/', substr($file, strlen(dirname($file)) + 1)); for ($i = 1, $c = count($folder_parts); $i <= $c; $i++) { chmod(dirname($file) . '/' . implode('/', array_slice($folder_parts, 0, $i)), $perms); } } } return true; } /** * Get cache directories and urls * * @return Array */ public static function cache_path() { // get latest time stamp $cache_time = wp_optimize_minify_config()->get('last-cache-update'); $cache_dir_url = WPO_CACHE_MIN_FILES_URL . "/$cache_time/assets"; $tmp_dir = WPO_CACHE_MIN_FILES_DIR . "/tmp"; $header_dir = WPO_CACHE_MIN_FILES_DIR . "/$cache_time/header"; $cache_dir = WPO_CACHE_MIN_FILES_DIR . "/$cache_time/assets"; // Create directories $dirs = array($cache_dir, $tmp_dir, $header_dir); foreach ($dirs as $target) { $enabled = wp_optimize_minify_config()->get('enabled'); if (false === $enabled) break; if (!is_dir($target) && !wp_mkdir_p($target)) { error_log('WP_Optimize_Minify_Cache_Functions::cache_path(): The folder "'.$target.'" could not be created.'); } } return array( 'tmpdir' => $tmp_dir, 'cachedir' => $cache_dir, 'cachedirurl' => $cache_dir_url, 'headerdir' => $header_dir ); } /** * Increment file names */ public static function cache_increment() { $stamp = time(); wp_optimize_minify_config()->update(array( 'last-cache-update' => $stamp )); return $stamp; } /** * Reset the cache (Increment + purge temp files) */ public static function reset() { self::cache_increment(); self::purge_temp_files(); } /** * Will delete temporary intermediate stuff but leave final css/js alone for compatibility * * @return Array */ public static function purge_temp_files() { // get cache directories and urls $cache_path = self::cache_path(); $tmp_dir = $cache_path['tmpdir']; $header_dir = $cache_path['headerdir']; // delete temporary directories only if (is_dir($tmp_dir)) { wpo_delete_files($tmp_dir, true); } if (is_dir($header_dir)) { wpo_delete_files($header_dir, true); } /** * Action triggered after purging temporary files */ do_action('wpo_min_after_purge_temp_files'); return array( 'tmpdir' => $tmp_dir, 'headerdir' => $header_dir, ); } /** * Purge supported hosting and plugins * * @return string */ public static function purge_others() { /** * Action triggered before purging other plugins cache */ do_action('wpo_min_before_purge_others'); // WordPress default cache if (function_exists('wp_cache_flush')) { wp_cache_flush(); } // Purge WP-Optimize WP_Optimize()->get_page_cache()->purge(); // When plugins have a simple method, add them to the array ('Plugin Name' => 'method_name') $others = array( 'WP Super Cache' => 'wp_cache_clear_cache', 'W3 Total Cache' => 'w3tc_pgcache_flush', 'WP Fastest Cache' => 'wpfc_clear_all_cache', 'WP Rocket' => 'rocket_clean_domain', 'Cachify' => 'cachify_flush_cache', 'Comet Cache' => array('comet_cache', 'clear'), 'SG Optimizer' => 'sg_cachepress_purge_cache', 'Pantheon' => 'pantheon_wp_clear_edge_all', 'Zen Cache' => array('zencache', 'clear'), 'Breeze' => array('Breeze_PurgeCache', 'breeze_cache_flush'), 'Swift Performance' => array('Swift_Performance_Cache', 'clear_all_cache'), ); foreach ($others as $plugin => $method) { if (is_callable($method)) { call_user_func($method); return sprintf(__('All caches from %s have also been purged.', 'wp-optimize'), ''.$plugin.''); } } // Purge LiteSpeed Cache if (is_callable(array('LiteSpeed_Cache_Tags', 'add_purge_tag'))) { LiteSpeed_Cache_Tags::add_purge_tag('*'); return sprintf(__('All caches from %s have also been purged.', 'wp-optimize'), 'LiteSpeed Cache'); } // Purge Hyper Cache if (class_exists('HyperCache')) { do_action('autoptimize_action_cachepurged'); return sprintf(__('All caches from %s have also been purged.', 'wp-optimize'), 'Hyper Cache'); } // Purge Godaddy Managed WordPress Hosting (Varnish + APC) if (class_exists('WPaaS\Plugin')) { self::godaddy_request('BAN'); return sprintf(__('A cache purge request has been sent to %s. Please note that it may not work every time, due to cache rate limiting by your host.', 'wp-optimize'), 'Go Daddy Varnish'); } // purge cache enabler if (has_action('ce_clear_cache')) { do_action('ce_clear_cache'); return sprintf(__('All caches from %s have also been purged.', 'wp-optimize'), 'Cache Enabler'); } // Purge WP Engine if (class_exists("WpeCommon")) { if (method_exists('WpeCommon', 'purge_memcached')) { WpeCommon::purge_memcached(); } if (method_exists('WpeCommon', 'clear_maxcdn_cache')) { WpeCommon::clear_maxcdn_cache(); } if (method_exists('WpeCommon', 'purge_varnish_cache')) { WpeCommon::purge_varnish_cache(); } if (method_exists('WpeCommon', 'purge_memcached') || method_exists('WpeCommon', 'clear_maxcdn_cache') || method_exists('WpeCommon', 'purge_varnish_cache')) { return sprintf(__('A cache purge request has been sent to %s. Please note that it may not work every time, due to cache rate limiting by your host.', 'wp-optimize'), 'WP Engine'); } } // Purge Kinsta global $kinsta_cache; if (isset($kinsta_cache) && class_exists('\\Kinsta\\CDN_Enabler')) { if (!empty($kinsta_cache->kinsta_cache_purge) && is_callable(array($kinsta_cache->kinsta_cache_purge, 'purge_complete_caches'))) { $kinsta_cache->kinsta_cache_purge->purge_complete_caches(); return sprintf(__('A cache purge request was also sent to %s', 'wp-optimize'), 'Kinsta'); } } // Purge Pagely if (class_exists('PagelyCachePurge')) { $purge_pagely = new PagelyCachePurge(); if (is_callable(array($purge_pagely, 'purgeAll'))) { $purge_pagely->purgeAll(); return sprintf(__('A cache purge request was also sent to %s', 'wp-optimize'), 'Pagely'); } } // Purge Pressidum if (defined('WP_NINUKIS_WP_NAME') && class_exists('Ninukis_Plugin') && is_callable(array('Ninukis_Plugin', 'get_instance'))) { $purge_pressidum = Ninukis_Plugin::get_instance(); if (is_callable(array($purge_pressidum, 'purgeAllCaches'))) { $purge_pressidum->purgeAllCaches(); return sprintf(__('A cache purge request was also sent to %s', 'wp-optimize'), 'Pressidium'); } } // Purge Savvii if (defined('\Savvii\CacheFlusherPlugin::NAME_DOMAINFLUSH_NOW')) { $purge_savvii = new \Savvii\CacheFlusherPlugin(); // phpcs:ignore PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ns_separatorFound if (is_callable(array($purge_savvii, 'domainflush'))) { $purge_savvii->domainflush(); return sprintf(__('A cache purge request was also sent to %s', 'wp-optimize'), 'Savvii'); } } /** * Action triggered when purging other plugins cache, and nothing was triggered */ do_action('wpo_min_after_purge_others'); } /** * Purge all public files on uninstallation * This will break cached pages that ref minified JS/CSS * * @return Boolean */ public static function purge() { $log = ''; if (is_dir(WPO_CACHE_MIN_FILES_DIR)) { if (wpo_delete_files(WPO_CACHE_MIN_FILES_DIR, true)) { $log = "[Minify] files and folders are deleted recursively"; } else { $log = "[Minify] recursive files and folders deletion unsuccessful"; } if (wp_optimize_minify_config()->get('debug')) { error_log($log); } } return true; } /** * Purge cache files older than 30 days * * @return array */ public static function purge_old() { if (!class_exists('WP_Optimize_Minify_Config')) { include_once WPO_PLUGIN_MAIN_PATH . '/minify/class-wp-optimize-minify-config.php'; } $cache_time = wp_optimize_minify_config()->get('last-cache-update'); $cache_lifespan = wp_optimize_minify_config()->get('cache_lifespan'); /** * Minify cache lifespan * * @param int The minify cache expiry timestamp */ $expires = apply_filters('wp_optimize_minify_cache_expiry_time', time() - 86400 * $cache_lifespan); $log = array(); // get all directories that are a direct child of current directory if (is_dir(WPO_CACHE_MIN_FILES_DIR) && is_writable(dirname(WPO_CACHE_MIN_FILES_DIR))) { if ($handle = opendir(WPO_CACHE_MIN_FILES_DIR)) { while (false !== ($d = readdir($handle))) { if (strcmp($d, '.')==0 || strcmp($d, '..')==0) { continue; } $log[] = "cache expiration time - $expires"; $log[] = "checking if cache has expired - $d"; if ($d != $cache_time && (is_numeric($d) && $d <= $expires)) { $dir = WPO_CACHE_MIN_FILES_DIR.'/'.$d; if (is_dir($dir)) { $log[] = "deleting cache in $dir"; if (wpo_delete_files($dir, true)) { $log[] = "files and folders are deleted recursively - $dir"; } else { $log[] = "recursive files and folders deletion unsuccessful - $dir"; } if (file_exists($dir)) { if (rmdir($dir)) { $log[] = "folder deleted successfully - $dir"; } else { $log[] = "folder deletion unsuccessful - $dir"; } } } } } closedir($handle); } } if (wp_optimize_minify_config()->get('debug')) { foreach ($log as $message) { error_log($message); } } return $log; } /** * Get transients from the disk * * @return String|Boolean */ public static function get_transient($key) { $cache_path = self::cache_path(); $tmp_dir = $cache_path['tmpdir']; $f = $tmp_dir.'/'.$key.'.transient'; clearstatcache(); if (file_exists($f)) { return file_get_contents($f); } else { return false; } } /** * Set cache on disk * * @param String $key * @param Mixed $code * * @return Boolean */ public static function set_transient($key, $code) { if (is_null($code) || empty($code)) { return false; } $cache_path = self::cache_path(); $tmp_dir = $cache_path['tmpdir']; $f = $tmp_dir.'/'.$key.'.transient'; file_put_contents($f, $code); self::fix_permission_bits($f); return true; } /** * Get the cache size and count * * @param string $folder * @return String */ public static function get_cachestats($folder) { clearstatcache(); if (is_dir($folder)) { $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder, FilesystemIterator::SKIP_DOTS)); $size = 0; $file_count = 0; foreach ($dir as $file) { $size += $file->getSize(); $file_count++; } return WP_Optimize()->format_size($size) . ' ('.$file_count.' files)'; } else { return sprintf(__('Error: %s is not a directory!', 'wp-optimize'), $folder); } } /** * Purge GoDaddy Managed WordPress Hosting (Varnish) * * Source: https://github.com/wp-media/wp-rocket/blob/master/inc/3rd-party/hosting/godaddy.php * * @param String $method * @param String|Null $url */ public static function godaddy_request($method, $url = null) { $url = empty($url) ? home_url() : $url; $host = parse_url($url, PHP_URL_HOST); $url = set_url_scheme(str_replace($host, WPaas\Plugin::vip(), $url), 'http'); // phpcs:ignore PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ns_separatorFound wp_cache_flush(); update_option('gd_system_last_cache_flush', time()); // purge apc wp_remote_request(esc_url_raw($url), array('method' => $method, 'blocking' => false, 'headers' => array('Host' => $host))); } /** * List all cache files * * @param integer $stamp A timestamp * @param boolean $use_cache If true, do not use transient value * @return array */ public static function get_cached_files($stamp = 0, $use_cache = true) { if ($use_cache && $files = get_transient('wpo_minify_get_cached_files')) { return $files; } $cache_path = self::cache_path(); $cache_dir = $cache_path['cachedir']; $size = self::get_cachestats($cache_dir); $total_size = self::get_cachestats(WPO_CACHE_MIN_FILES_DIR); $o = wp_optimize_minify_config()->get(); $cache_time = (0 == $o['last-cache-update']) ? __('Never.', 'wp-optimize') : self::format_date_time($o['last-cache-update']); $return = array( 'js' => array(), 'css' => array(), 'stamp' => $stamp, 'cachesize' => esc_html($size), 'total_cache_size' => esc_html($total_size), 'cacheTime' => $cache_time, 'cachePath' => $cache_path['cachedir'] ); // Inspect directory with opendir, since glob might not be available in some systems clearstatcache(); if (is_dir($cache_dir.'/') && $handle = opendir($cache_dir.'/')) { while (false !== ($file = readdir($handle))) { $file = $cache_dir.'/'.$file; $ext = pathinfo($file, PATHINFO_EXTENSION); if (in_array($ext, array('js', 'css'))) { $log = false; if (file_exists($file.'.json')) { $log = json_decode(file_get_contents($file.'.json')); } $min_css = substr($file, 0, -4).'.min.css'; $minjs = substr($file, 0, -3).'.min.js'; $file_name = basename($file); $file_url = trailingslashit($cache_path['cachedirurl']).$file_name; if ('css' == $ext && file_exists($min_css)) { $file_name = basename($min_css); } if ('js' == $ext && file_exists($minjs)) { $file_name = basename($minjs); } $file_size = WP_Optimize()->format_size(filesize($file)); $uid = hash('adler32', $file_name); array_push($return[$ext], array('uid' => $uid, 'filename' => $file_name, 'file_url' => $file_url, 'log' => $log, 'fsize' => $file_size)); } } closedir($handle); } set_transient('wpo_minify_get_cached_files', $return, DAY_IN_SECONDS); return $return; } /** * Format a timestamp using WP's date_format and time_format * * @param integer $timestamp - The timestamp * @return string */ public static function format_date_time($timestamp) { return WP_Optimize()->format_date_time($timestamp); } /** * Format the log created when merging assets. Called via array_map * * @param array $files The files array, containing the 'log' object or array. * @return array */ public static function format_file_logs($files) { $files['log'] = WP_Optimize()->include_template( 'minify/cached-file-log.php', true, array( 'log' => $files['log'], 'minify_config' => wp_optimize_minify_config()->get(), ) ); return $files; } } /** * Astra Updates * * Functions for updating data, used by the background updater. * * @package Astra * @version 2.1.3 */ defined( 'ABSPATH' ) || exit; /** * Open Submenu just below menu for existing users. * * @since 2.1.3 * @return void */ function astra_submenu_below_header() { $theme_options = get_option( 'astra-settings' ); // Set flag to use flex align center css to open submenu just below menu. if ( ! isset( $theme_options['submenu-open-below-header'] ) ) { $theme_options['submenu-open-below-header'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Do not apply new default colors to the Elementor & Gutenberg Buttons for existing users. * * @since 2.2.0 * * @return void */ function astra_page_builder_button_color_compatibility() { $theme_options = get_option( 'astra-settings', array() ); // Set flag to not load button specific CSS. if ( ! isset( $theme_options['pb-button-color-compatibility'] ) ) { $theme_options['pb-button-color-compatibility'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Migrate option data from button vertical & horizontal padding to the new responsive padding param. * * @since 2.2.0 * * @return void */ function astra_vertical_horizontal_padding_migration() { $theme_options = get_option( 'astra-settings', array() ); $btn_vertical_padding = isset( $theme_options['button-v-padding'] ) ? $theme_options['button-v-padding'] : 10; $btn_horizontal_padding = isset( $theme_options['button-h-padding'] ) ? $theme_options['button-h-padding'] : 40; /** @psalm-suppress InvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort if ( false === astra_get_db_option( 'theme-button-padding', false ) ) { // Migrate button vertical padding to the new padding param for button. $theme_options['theme-button-padding'] = array( 'desktop' => array( 'top' => $btn_vertical_padding, 'right' => $btn_horizontal_padding, 'bottom' => $btn_vertical_padding, 'left' => $btn_horizontal_padding, ), 'tablet' => array( 'top' => '', 'right' => '', 'bottom' => '', 'left' => '', ), 'mobile' => array( 'top' => '', 'right' => '', 'bottom' => '', 'left' => '', ), 'desktop-unit' => 'px', 'tablet-unit' => 'px', 'mobile-unit' => 'px', ); update_option( 'astra-settings', $theme_options ); } } /** * Migrate option data from button url to the new link param. * * @since 2.3.0 * * @return void */ function astra_header_button_new_options() { $theme_options = get_option( 'astra-settings', array() ); $btn_url = isset( $theme_options['header-main-rt-section-button-link'] ) ? $theme_options['header-main-rt-section-button-link'] : 'https://www.wpastra.com'; $theme_options['header-main-rt-section-button-link-option'] = array( 'url' => $btn_url, 'new_tab' => false, 'link_rel' => '', ); update_option( 'astra-settings', $theme_options ); } /** * For existing users, do not provide Elementor Default Color Typo settings compatibility by default. * * @since 2.3.3 * * @return void */ function astra_elementor_default_color_typo_comp() { $theme_options = get_option( 'astra-settings', array() ); // Set flag to not load button specific CSS. if ( ! isset( $theme_options['ele-default-color-typo-setting-comp'] ) ) { $theme_options['ele-default-color-typo-setting-comp'] = false; update_option( 'astra-settings', $theme_options ); } } /** * For existing users, change the separator from html entity to css entity. * * @since 2.3.4 * * @return void */ function astra_breadcrumb_separator_fix() { $theme_options = get_option( 'astra-settings', array() ); // Check if the saved database value for Breadcrumb Separator is "»", then change it to '\00bb'. if ( isset( $theme_options['breadcrumb-separator'] ) && '»' === $theme_options['breadcrumb-separator'] ) { $theme_options['breadcrumb-separator'] = '\00bb'; update_option( 'astra-settings', $theme_options ); } } /** * Check if we need to change the default value for tablet breakpoint. * * @since 2.4.0 * @return void */ function astra_update_theme_tablet_breakpoint() { $theme_options = get_option( 'astra-settings' ); if ( ! isset( $theme_options['can-update-theme-tablet-breakpoint'] ) ) { // Set a flag to check if we need to change the theme tablet breakpoint value. $theme_options['can-update-theme-tablet-breakpoint'] = false; } update_option( 'astra-settings', $theme_options ); } /** * Migrate option data from site layout background option to its desktop counterpart. * * @since 2.4.0 * * @return void */ function astra_responsive_base_background_option() { $theme_options = get_option( 'astra-settings', array() ); if ( false === get_option( 'site-layout-outside-bg-obj-responsive', false ) && isset( $theme_options['site-layout-outside-bg-obj'] ) ) { $theme_options['site-layout-outside-bg-obj-responsive']['desktop'] = $theme_options['site-layout-outside-bg-obj']; $theme_options['site-layout-outside-bg-obj-responsive']['tablet'] = array( 'background-color' => '', 'background-image' => '', 'background-repeat' => 'repeat', 'background-position' => 'center center', 'background-size' => 'auto', 'background-attachment' => 'scroll', ); $theme_options['site-layout-outside-bg-obj-responsive']['mobile'] = array( 'background-color' => '', 'background-image' => '', 'background-repeat' => 'repeat', 'background-position' => 'center center', 'background-size' => 'auto', 'background-attachment' => 'scroll', ); } update_option( 'astra-settings', $theme_options ); } /** * Do not apply new wide/full image CSS for existing users. * * @since 2.4.4 * * @return void */ function astra_gtn_full_wide_image_group_css() { $theme_options = get_option( 'astra-settings', array() ); // Set flag to not load button specific CSS. if ( ! isset( $theme_options['gtn-full-wide-image-grp-css'] ) ) { $theme_options['gtn-full-wide-image-grp-css'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Do not apply new wide/full Group and Cover block CSS for existing users. * * @since 2.5.0 * * @return void */ function astra_gtn_full_wide_group_cover_css() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['gtn-full-wide-grp-cover-css'] ) ) { $theme_options['gtn-full-wide-grp-cover-css'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Do not apply the global border width and border color setting for the existng users. * * @since 2.5.0 * * @return void */ function astra_global_button_woo_css() { $theme_options = get_option( 'astra-settings', array() ); // Set flag to not load button specific CSS. if ( ! isset( $theme_options['global-btn-woo-css'] ) ) { $theme_options['global-btn-woo-css'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Migrate Footer Widget param to array. * * @since 2.5.2 * * @return void */ function astra_footer_widget_bg() { $theme_options = get_option( 'astra-settings', array() ); // Check if Footer Backgound array is already set or not. If not then set it as array. if ( isset( $theme_options['footer-adv-bg-obj'] ) && ! is_array( $theme_options['footer-adv-bg-obj'] ) ) { $theme_options['footer-adv-bg-obj'] = array( 'background-color' => '', 'background-image' => '', 'background-repeat' => 'repeat', 'background-position' => 'center center', 'background-size' => 'auto', 'background-attachment' => 'scroll', ); update_option( 'astra-settings', $theme_options ); } } /** * Check if we need to load icons as font or SVG. * * @since 3.3.0 * @return void */ function astra_icons_svg_compatibility() { $theme_options = get_option( 'astra-settings' ); if ( ! isset( $theme_options['can-update-astra-icons-svg'] ) ) { // Set a flag to check if we need to add icons as SVG. $theme_options['can-update-astra-icons-svg'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Migrate Background control options to new array. * * @since 3.0.0 * * @return void */ function astra_bg_control_migration() { $db_options = array( 'footer-adv-bg-obj', 'footer-bg-obj', 'sidebar-bg-obj', ); $theme_options = get_option( 'astra-settings', array() ); foreach ( $db_options as $option_name ) { if ( ! ( isset( $theme_options[ $option_name ]['background-type'] ) && isset( $theme_options[ $option_name ]['background-media'] ) ) && isset( $theme_options[ $option_name ] ) ) { if ( ! empty( $theme_options[ $option_name ]['background-image'] ) ) { $theme_options[ $option_name ]['background-type'] = 'image'; $theme_options[ $option_name ]['background-media'] = attachment_url_to_postid( $theme_options[ $option_name ]['background-image'] ); } else { $theme_options[ $option_name ]['background-type'] = ''; $theme_options[ $option_name ]['background-media'] = ''; } error_log( sprintf( 'Astra: Migrating Background Option - %s', $option_name ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log update_option( 'astra-settings', $theme_options ); } } } /** * Migrate Background Responsive options to new array. * * @since 3.0.0 * * @return void */ function astra_bg_responsive_control_migration() { $db_options = array( 'site-layout-outside-bg-obj-responsive', 'content-bg-obj-responsive', 'header-bg-obj-responsive', 'primary-menu-bg-obj-responsive', 'above-header-bg-obj-responsive', 'above-header-menu-bg-obj-responsive', 'below-header-bg-obj-responsive', 'below-header-menu-bg-obj-responsive', ); $theme_options = get_option( 'astra-settings', array() ); foreach ( $db_options as $option_name ) { if ( ! ( isset( $theme_options[ $option_name ]['desktop']['background-type'] ) && isset( $theme_options[ $option_name ]['desktop']['background-media'] ) ) && isset( $theme_options[ $option_name ] ) ) { if ( ! empty( $theme_options[ $option_name ]['desktop']['background-image'] ) ) { $theme_options[ $option_name ]['desktop']['background-type'] = 'image'; $theme_options[ $option_name ]['desktop']['background-media'] = attachment_url_to_postid( $theme_options[ $option_name ]['desktop']['background-image'] ); } else { $theme_options[ $option_name ]['desktop']['background-type'] = ''; $theme_options[ $option_name ]['desktop']['background-media'] = ''; } if ( ! empty( $theme_options[ $option_name ]['tablet']['background-image'] ) ) { $theme_options[ $option_name ]['tablet']['background-type'] = 'image'; $theme_options[ $option_name ]['tablet']['background-media'] = attachment_url_to_postid( $theme_options[ $option_name ]['tablet']['background-image'] ); } else { $theme_options[ $option_name ]['tablet']['background-type'] = ''; $theme_options[ $option_name ]['tablet']['background-media'] = ''; } if ( ! empty( $theme_options[ $option_name ]['mobile']['background-image'] ) ) { $theme_options[ $option_name ]['mobile']['background-type'] = 'image'; $theme_options[ $option_name ]['mobile']['background-media'] = attachment_url_to_postid( $theme_options[ $option_name ]['mobile']['background-image'] ); } else { $theme_options[ $option_name ]['mobile']['background-type'] = ''; $theme_options[ $option_name ]['mobile']['background-media'] = ''; } error_log( sprintf( 'Astra: Migrating Background Response Option - %s', $option_name ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log update_option( 'astra-settings', $theme_options ); } } } /** * Do not apply new Group, Column and Media & Text block CSS for existing users. * * @since 3.0.0 * * @return void */ function astra_gutenberg_core_blocks_design_compatibility() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['guntenberg-core-blocks-comp-css'] ) ) { $theme_options['guntenberg-core-blocks-comp-css'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Header Footer builder - Migration compatibility. * * @since 3.0.0 * * @return void */ function astra_header_builder_compatibility() { $theme_options = get_option( 'astra-settings', array() ); // Set flag to not load button specific CSS. if ( ! isset( $theme_options['is-header-footer-builder'] ) ) { $theme_options['is-header-footer-builder'] = false; update_option( 'astra-settings', $theme_options ); } if ( ! isset( $theme_options['header-footer-builder-notice'] ) ) { $theme_options['header-footer-builder-notice'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Clears assets cache and regenerates new assets files. * * @since 3.0.1 * * @return void */ function astra_clear_assets_cache() { if ( is_callable( 'Astra_Minify::refresh_assets' ) ) { Astra_Minify::refresh_assets(); } } /** * Do not apply new Media & Text block padding CSS & not remove padding for #primary on mobile devices directly for existing users. * * @since 2.6.1 * * @return void */ function astra_gutenberg_media_text_block_css_compatibility() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['guntenberg-media-text-block-padding-css'] ) ) { $theme_options['guntenberg-media-text-block-padding-css'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Gutenberg pattern compatibility changes. * * @since 3.3.0 * * @return void */ function astra_gutenberg_pattern_compatibility() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['guntenberg-button-pattern-compat-css'] ) ) { $theme_options['guntenberg-button-pattern-compat-css'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Set flag to provide backward compatibility of float based CSS for existing users. * * @since 3.3.0 * @return void. */ function astra_check_flex_based_css() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['is-flex-based-css'] ) ) { $theme_options['is-flex-based-css'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Update the Cart Style, Icon color & Border radius if None style is selected. * * @since 3.4.0 * @return void. */ function astra_update_cart_style() { $theme_options = get_option( 'astra-settings', array() ); if ( isset( $theme_options['woo-header-cart-icon-style'] ) && 'none' === $theme_options['woo-header-cart-icon-style'] ) { $theme_options['woo-header-cart-icon-style'] = 'outline'; $theme_options['header-woo-cart-icon-color'] = ''; $theme_options['woo-header-cart-icon-color'] = ''; $theme_options['woo-header-cart-icon-radius'] = ''; } if ( isset( $theme_options['edd-header-cart-icon-style'] ) && 'none' === $theme_options['edd-header-cart-icon-style'] ) { $theme_options['edd-header-cart-icon-style'] = 'outline'; $theme_options['edd-header-cart-icon-color'] = ''; $theme_options['edd-header-cart-icon-radius'] = ''; } update_option( 'astra-settings', $theme_options ); } /** * Update existing 'Grid Column Layout' option in responsive way in Related Posts. * Till this update 3.5.0 we have 'Grid Column Layout' only for singular option, but now we are improving it as responsive. * * @since 3.5.0 * @return void. */ function astra_update_related_posts_grid_layout() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['related-posts-grid-responsive'] ) && isset( $theme_options['related-posts-grid'] ) ) { /** * Managed here switch case to reduce further conditions in dynamic-css to get CSS value based on grid-template-columns. Because there are following CSS props used. * * '1' = grid-template-columns: 1fr; * '2' = grid-template-columns: repeat(2,1fr); * '3' = grid-template-columns: repeat(3,1fr); * '4' = grid-template-columns: repeat(4,1fr); * * And we already have Astra_Builder_Helper::$grid_size_mapping (used for footer layouts) for getting CSS values based on grid layouts. So migrating old value of grid here to new grid value. */ switch ( $theme_options['related-posts-grid'] ) { case '1': $grid_layout = 'full'; break; case '2': $grid_layout = '2-equal'; break; case '3': $grid_layout = '3-equal'; break; case '4': $grid_layout = '4-equal'; break; } $theme_options['related-posts-grid-responsive'] = array( 'desktop' => $grid_layout, 'tablet' => $grid_layout, 'mobile' => 'full', ); update_option( 'astra-settings', $theme_options ); } } /** * Migrate Site Title & Site Tagline options to new responsive array. * * @since 3.5.0 * * @return void */ function astra_site_title_tagline_responsive_control_migration() { $theme_options = get_option( 'astra-settings', array() ); if ( false === get_option( 'display-site-title-responsive', false ) && isset( $theme_options['display-site-title'] ) ) { $theme_options['display-site-title-responsive']['desktop'] = $theme_options['display-site-title']; $theme_options['display-site-title-responsive']['tablet'] = $theme_options['display-site-title']; $theme_options['display-site-title-responsive']['mobile'] = $theme_options['display-site-title']; } if ( false === get_option( 'display-site-tagline-responsive', false ) && isset( $theme_options['display-site-tagline'] ) ) { $theme_options['display-site-tagline-responsive']['desktop'] = $theme_options['display-site-tagline']; $theme_options['display-site-tagline-responsive']['tablet'] = $theme_options['display-site-tagline']; $theme_options['display-site-tagline-responsive']['mobile'] = $theme_options['display-site-tagline']; } update_option( 'astra-settings', $theme_options ); } /** * Do not apply new font-weight heading support CSS in editor/frontend directly. * * 1. Adding Font-weight support to widget titles. * 2. Customizer font CSS not supporting in editor. * * @since 3.6.0 * * @return void */ function astra_headings_font_support() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['can-support-widget-and-editor-fonts'] ) ) { $theme_options['can-support-widget-and-editor-fonts'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Set flag to avoid direct reflections on live site & to maintain backward compatibility for existing users. * * @since 3.6.0 * @return void. */ function astra_remove_logo_max_width() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['can-remove-logo-max-width-css'] ) ) { $theme_options['can-remove-logo-max-width-css'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Set flag to maintain backward compatibility for existing users for Transparent Header border bottom default value i.e from '' to 0. * * @since 3.6.0 * @return void. */ function astra_transparent_header_default_value() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['transparent-header-default-border'] ) ) { $theme_options['transparent-header-default-border'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Clear Astra + Astra Pro assets cache. * * @since 3.6.1 * @return void. */ function astra_clear_all_assets_cache() { if ( ! class_exists( 'Astra_Cache_Base' ) ) { return; } // Clear Astra theme asset cache. $astra_cache_base_instance = new Astra_Cache_Base( 'astra' ); $astra_cache_base_instance->refresh_assets( 'astra' ); // Clear Astra Addon's static and dynamic CSS asset cache. astra_clear_assets_cache(); $astra_addon_cache_base_instance = new Astra_Cache_Base( 'astra-addon' ); $astra_addon_cache_base_instance->refresh_assets( 'astra-addon' ); } /** * Set flag for updated default values for buttons & add GB Buttons padding support. * * @since 3.6.3 * @return void */ function astra_button_default_values_updated() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['btn-default-padding-updated'] ) ) { $theme_options['btn-default-padding-updated'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Set flag for old users, to not directly apply underline to content links. * * @since 3.6.4 * @return void */ function astra_update_underline_link_setting() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['underline-content-links'] ) ) { $theme_options['underline-content-links'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Add compatibility support for WP-5.8. as some of settings & blocks already their in WP-5.7 versions, that's why added backward here. * * @since 3.6.5 * @return void */ function astra_support_block_editor() { $theme_options = get_option( 'astra-settings' ); // Set flag on existing user's site to not reflect changes directly. if ( ! isset( $theme_options['support-block-editor'] ) ) { $theme_options['support-block-editor'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Set flag to maintain backward compatibility for existing users. * Fixing the case where footer widget's right margin space not working. * * @since 3.6.7 * @return void */ function astra_fix_footer_widget_right_margin_case() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['support-footer-widget-right-margin'] ) ) { $theme_options['support-footer-widget-right-margin'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Set flag to avoid direct reflections on live site & to maintain backward compatibility for existing users. * * @since 3.6.7 * @return void */ function astra_remove_elementor_toc_margin() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['remove-elementor-toc-margin-css'] ) ) { $theme_options['remove-elementor-toc-margin-css'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Set flag to avoid direct reflections on live site & to maintain backward compatibility for existing users. * Use: Setting flag for removing widget specific design options when WordPress 5.8 & above activated on site. * * @since 3.6.8 * @return void */ function astra_set_removal_widget_design_options_flag() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['remove-widget-design-options'] ) ) { $theme_options['remove-widget-design-options'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Apply zero font size for new users. * * @since 3.6.9 * @return void */ function astra_zero_font_size_comp() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['astra-zero-font-size-case-css'] ) ) { $theme_options['astra-zero-font-size-case-css'] = false; update_option( 'astra-settings', $theme_options ); } } /** Set flag to avoid direct reflections on live site & to maintain backward compatibility for existing users. * * @since 3.6.9 * @return void */ function astra_unset_builder_elements_underline() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['unset-builder-elements-underline'] ) ) { $theme_options['unset-builder-elements-underline'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Migrating Builder > Account > transparent resonsive menu color options to single color options. * Because we do not show menu on resonsive devices, whereas we trigger login link on responsive devices instead of showing menu. * * @since 3.6.9 * * @return void */ function astra_remove_responsive_account_menu_colors_support() { $theme_options = get_option( 'astra-settings', array() ); $account_menu_colors = array( 'transparent-account-menu-color', // Menu color. 'transparent-account-menu-bg-obj', // Menu background color. 'transparent-account-menu-h-color', // Menu hover color. 'transparent-account-menu-h-bg-color', // Menu background hover color. 'transparent-account-menu-a-color', // Menu active color. 'transparent-account-menu-a-bg-color', // Menu background active color. ); foreach ( $account_menu_colors as $color_option ) { if ( ! isset( $theme_options[ $color_option ] ) && isset( $theme_options[ $color_option . '-responsive' ]['desktop'] ) ) { $theme_options[ $color_option ] = $theme_options[ $color_option . '-responsive' ]['desktop']; } } update_option( 'astra-settings', $theme_options ); } /** * Link default color compatibility. * * @since 3.7.0 * @return void */ function astra_global_color_compatibility() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['support-global-color-format'] ) ) { $theme_options['support-global-color-format'] = false; } // Set Footer copyright text color for existing users to #3a3a3a. if ( ! isset( $theme_options['footer-copyright-color'] ) ) { $theme_options['footer-copyright-color'] = '#3a3a3a'; } update_option( 'astra-settings', $theme_options ); } /** * Set flag to avoid direct reflections on live site & to maintain backward compatibility for existing users. * * @since 3.7.4 * @return void */ function astra_improve_gutenberg_editor_ui() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['improve-gb-editor-ui'] ) ) { $theme_options['improve-gb-editor-ui'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Set flag to avoid direct reflections on live site & to maintain backward compatibility for existing users. * * Starting supporting content-background color for Full Width Contained & Full Width Stretched layouts. * * @since 3.7.8 * @return void */ function astra_fullwidth_layouts_apply_content_background() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['apply-content-background-fullwidth-layouts'] ) ) { $theme_options['apply-content-background-fullwidth-layouts'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Sets the default breadcrumb separator selector value if the current user is an exsisting user * * @since 3.7.8 * @return void */ function astra_set_default_breadcrumb_separator_option() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['breadcrumb-separator-selector'] ) ) { $theme_options['breadcrumb-separator-selector'] = 'unicode'; update_option( 'astra-settings', $theme_options ); } } /** * Set flag to avoid direct reflections on live site & to maintain backward compatibility for existing users. * * Backward flag purpose - To initiate modern & updated UI of block editor & frontend. * * @since 3.8.0 * @return void */ function astra_apply_modern_block_editor_ui() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['wp-blocks-ui'] ) && ! version_compare( $theme_options['theme-auto-version'], '3.8.0', '==' ) ) { $theme_options['blocks-legacy-setup'] = true; $theme_options['wp-blocks-ui'] = 'legacy'; update_option( 'astra-settings', $theme_options ); } } /** * Set flag to avoid direct reflections on live site & to maintain backward compatibility for existing users. * * Backward flag purpose - To keep structure defaults updation by filter. * * @since 3.8.3 * @return void */ function astra_update_customizer_layout_defaults() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['customizer-default-layout-update'] ) ) { $theme_options['customizer-default-layout-update'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Set flag to avoid direct reflections on live site & to maintain backward compatibility for existing users. * * Backward flag purpose - To initiate maintain modern, updated v2 experience of block editor & frontend. * * @since 3.8.3 * @return void */ function astra_apply_modern_block_editor_v2_ui() { $theme_options = get_option( 'astra-settings', array() ); $option_updated = false; if ( ! isset( $theme_options['wp-blocks-v2-ui'] ) ) { $theme_options['wp-blocks-v2-ui'] = false; $option_updated = true; } if ( ! isset( $theme_options['wp-blocks-ui'] ) ) { $theme_options['wp-blocks-ui'] = 'custom'; $option_updated = true; } if ( $option_updated ) { update_option( 'astra-settings', $theme_options ); } } /** * Display Cart Total and Title compatibility. * * @since 3.9.0 * @return void */ function astra_display_cart_total_title_compatibility() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['woo-header-cart-label-display'] ) ) { // Set the Display Cart Label toggle values with shortcodes. $cart_total_status = isset( $theme_options['woo-header-cart-total-display'] ) ? $theme_options['woo-header-cart-total-display'] : true; $cart_label_status = isset( $theme_options['woo-header-cart-title-display'] ) ? $theme_options['woo-header-cart-title-display'] : true; if ( $cart_total_status && $cart_label_status ) { $theme_options['woo-header-cart-label-display'] = __( 'Cart', 'astra' ) . '/{cart_total_currency_symbol}'; } elseif ( $cart_total_status ) { $theme_options['woo-header-cart-label-display'] = '{cart_total_currency_symbol}'; } elseif ( $cart_label_status ) { $theme_options['woo-header-cart-label-display'] = __( 'Cart', 'astra' ); } update_option( 'astra-settings', $theme_options ); } } /** * If old user then it keeps then default cart icon. * * @since 3.9.0 * @return void */ function astra_update_woocommerce_cart_icons() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['astra-woocommerce-cart-icons-flag'] ) ) { $theme_options['astra-woocommerce-cart-icons-flag'] = false; } } /** * Set brder color to blank for old users for new users 'default' will take over. * * @since 3.9.0 * @return void */ function astra_legacy_customizer_maintenance() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['border-color'] ) ) { $theme_options['border-color'] = '#dddddd'; update_option( 'astra-settings', $theme_options ); } } /** * Enable single product breadcrumb to maintain backward compatibility for existing users. * * @since 3.9.0 * @return void */ function astra_update_single_product_breadcrumb() { $theme_options = get_option( 'astra-settings', array() ); if ( isset( $theme_options['single-product-breadcrumb-disable'] ) ) { $theme_options['single-product-breadcrumb-disable'] = ( true === $theme_options['single-product-breadcrumb-disable'] ) ? false : true; } else { $theme_options['single-product-breadcrumb-disable'] = true; } update_option( 'astra-settings', $theme_options ); } /** * Restrict direct changes on users end so make it filterable. * * @since 3.9.0 * @return void */ function astra_apply_modern_ecommerce_setup() { $theme_options = get_option( 'astra-settings', array() ); if ( ! isset( $theme_options['modern-ecommerce-setup'] ) ) { $theme_options['modern-ecommerce-setup'] = false; update_option( 'astra-settings', $theme_options ); } } /** * Admin functions - Functions that add some functionality to WordPress admin panel * * @package Astra * @since 1.0.0 */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Register menus */ if ( ! function_exists( 'astra_register_menu_locations' ) ) { /** * Register menus * * @since 1.0.0 */ function astra_register_menu_locations() { /** * Primary Menus */ register_nav_menus( array( 'primary' => __( 'Primary Menu', 'astra' ), ) ); if ( true === Astra_Builder_Helper::$is_header_footer_builder_active ) { /** * Register the Secondary & Mobile menus. */ register_nav_menus( array( 'secondary_menu' => __( 'Secondary Menu', 'astra' ), 'mobile_menu' => __( 'Off-Canvas Menu', 'astra' ), ) ); $component_limit = defined( 'ASTRA_EXT_VER' ) ? Astra_Builder_Helper::$component_limit : Astra_Builder_Helper::$num_of_header_menu; for ( $index = 3; $index <= $component_limit; $index++ ) { if ( ! is_customize_preview() && ! Astra_Builder_Helper::is_component_loaded( 'menu-' . $index ) ) { continue; } register_nav_menus( array( 'menu_' . $index => __( 'Menu ', 'astra' ) . $index, ) ); } /** * Register the Account menus. */ register_nav_menus( array( 'loggedin_account_menu' => __( 'Logged In Account Menu', 'astra' ), ) ); } /** * Footer Menus */ register_nav_menus( array( 'footer_menu' => __( 'Footer Menu', 'astra' ), ) ); } } add_action( 'init', 'astra_register_menu_locations' ); !function(global,factory){"function"==typeof define&&define.amd?define("ev-emitter/ev-emitter",factory):"object"==typeof module&&module.exports?module.exports=factory():global.EvEmitter=factory()}(this,function(){function EvEmitter(){}var proto=EvEmitter.prototype;return proto.on=function(eventName,listener){if(eventName&&listener){var events=this._events=this._events||{},listeners=events[eventName]=events[eventName]||[];return listeners.indexOf(listener)==-1&&listeners.push(listener),this}},proto.once=function(eventName,listener){if(eventName&&listener){this.on(eventName,listener);var onceEvents=this._onceEvents=this._onceEvents||{},onceListeners=onceEvents[eventName]=onceEvents[eventName]||[];return onceListeners[listener]=!0,this}},proto.off=function(eventName,listener){var listeners=this._events&&this._events[eventName];if(listeners&&listeners.length){var index=listeners.indexOf(listener);return index!=-1&&listeners.splice(index,1),this}},proto.emitEvent=function(eventName,args){var listeners=this._events&&this._events[eventName];if(listeners&&listeners.length){var i=0,listener=listeners[i];args=args||[];for(var onceListeners=this._onceEvents&&this._onceEvents[eventName];listener;){var isOnce=onceListeners&&onceListeners[listener];isOnce&&(this.off(eventName,listener),delete onceListeners[listener]),listener.apply(this,args),i+=isOnce?0:1,listener=listeners[i]}return this}},EvEmitter}),function(window,factory){"use strict";"function"==typeof define&&define.amd?define(["ev-emitter/ev-emitter"],function(EvEmitter){return factory(window,EvEmitter)}):"object"==typeof module&&module.exports?module.exports=factory(window,require("ev-emitter")):window.imagesLoaded=factory(window,window.EvEmitter)}(window,function(window,EvEmitter){function extend(a,b){for(var prop in b)a[prop]=b[prop];return a}function makeArray(obj){var ary=[];if(Array.isArray(obj))ary=obj;else if("number"==typeof obj.length)for(var i=0;i/** * Deprecated Functions of Astra Theme. * * @package Astra * @author Astra * @copyright Copyright (c) 2020, Astra * @link https://wpastra.com/ * @since Astra 1.0.23 */ if ( ! defined( 'ABSPATH' ) ) { exit; } if ( ! function_exists( 'astra_blog_post_thumbnai_and_title_order' ) ) : /** * Blog post thumbnail & title order * * @since 1.4.9 * @deprecated 1.4.9 Use astra_blog_post_thumbnail_and_title_order() * @see astra_blog_post_thumbnail_and_title_order() * * @return void */ function astra_blog_post_thumbnai_and_title_order() { _deprecated_function( __FUNCTION__, '1.4.9', 'astra_blog_post_thumbnail_and_title_order()' ); astra_blog_post_thumbnail_and_title_order(); } endif; if ( ! function_exists( 'get_astra_secondary_class' ) ) : /** * Retrieve the classes for the secondary element as an array. * * @since 1.5.2 * @deprecated 1.5.2 Use astra_get_secondary_class() * @param string|array $class One or more classes to add to the class list. * @see astra_get_secondary_class() * * @return array */ function get_astra_secondary_class( $class = '' ) { _deprecated_function( __FUNCTION__, '1.5.2', 'astra_get_secondary_class()' ); return astra_get_secondary_class( $class ); } endif; if ( ! function_exists( 'deprecated_astra_color_palette' ) ) : /** * Depreciating astra_color_palletes filter. * * @since 1.5.2 * @deprecated 1.5.2 Use astra_deprecated_color_palette() * @param array $color_palette customizer color palettes. * @see astra_deprecated_color_palette() * * @return array */ function deprecated_astra_color_palette( $color_palette ) { _deprecated_function( __FUNCTION__, '1.5.2', 'astra_deprecated_color_palette()' ); return astra_deprecated_color_palette( $color_palette ); } endif; if ( ! function_exists( 'deprecated_astra_sigle_post_navigation_enabled' ) ) : /** * Deprecating astra_sigle_post_navigation_enabled filter. * * @since 1.5.2 * @deprecated 1.5.2 Use astra_deprecated_sigle_post_navigation_enabled() * @param boolean $post_nav true | false. * @see astra_deprecated_sigle_post_navigation_enabled() * * @return array */ function deprecated_astra_sigle_post_navigation_enabled( $post_nav ) { _deprecated_function( __FUNCTION__, '1.5.2', 'astra_deprecated_sigle_post_navigation_enabled()' ); return astra_deprecated_sigle_post_navigation_enabled( $post_nav ); } endif; if ( ! function_exists( 'deprecated_astra_primary_header_main_rt_section' ) ) : /** * Deprecating astra_primary_header_main_rt_section filter. * * @since 1.5.2 * @deprecated 1.5.2 Use astra_deprecated_primary_header_main_rt_section() * @param array $elements List of elements. * @param string $header Header section type. * @see astra_deprecated_primary_header_main_rt_section() * * @return array */ function deprecated_astra_primary_header_main_rt_section( $elements, $header ) { _deprecated_function( __FUNCTION__, '1.5.2', 'astra_deprecated_primary_header_main_rt_section()' ); return astra_deprecated_primary_header_main_rt_section( $elements, $header ); } endif; if ( ! function_exists( 'astar' ) ) : /** * Get a specific property of an array without needing to check if that property exists. * * @since 1.5.2 * @deprecated 1.5.2 Use astra_get_prop() * @param array $array Array from which the property's value should be retrieved. * @param string $prop Name of the property to be retrieved. * @param string $default Optional. Value that should be returned if the property is not set or empty. Defaults to null. * @see astra_get_prop() * * @return null|string|mixed The value */ function astar( $array, $prop, $default = null ) { return astra_get_prop( $array, $prop, $default ); } endif; /** * Check if we're being delivered AMP. * * @return bool */ function astra_is_emp_endpoint() { _deprecated_function( __FUNCTION__, '2.0.1', 'astra_is_amp_endpoint()' ); return astra_is_amp_endpoint(); } /** * Deprecating footer_menu_static_css function. * * Footer menu specific static CSS function. * * @since 3.7.4 * @deprecated footer_menu_static_css() Use astra_footer_menu_static_css() * @see astra_footer_menu_static_css() * * @return string Parsed CSS */ function footer_menu_static_css() { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_footer_menu_static_css()' ); return astra_footer_menu_static_css(); } /** * Deprecating is_support_footer_widget_right_margin function. * * Backward managing function based on flag - 'support-footer-widget-right-margin' which fixes right margin issue in builder widgets. * * @since 3.7.4 * @deprecated is_support_footer_widget_right_margin() Use astra_support_footer_widget_right_margin() * @see astra_support_footer_widget_right_margin() * * @return bool true|false */ function is_support_footer_widget_right_margin() { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_support_footer_widget_right_margin()' ); return astra_support_footer_widget_right_margin(); } /** * Deprecating is_astra_addon_3_5_0_version function. * * Checking if Astra Addon is of v3.5.0 or on higher version. * * @since 3.7.4 * @deprecated is_astra_addon_3_5_0_version() Use astra_addon_has_3_5_0_version() * @see astra_addon_has_3_5_0_version() * * @return bool true|false based on version_compare of ASTRA_EXT_VER */ function is_astra_addon_3_5_0_version() { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_addon_has_3_5_0_version()' ); return astra_addon_has_3_5_0_version(); } /** * Deprecating prepare_button_defaults function. * * Default configurations for builder button components. * * @since 3.7.4 * @deprecated prepare_button_defaults() Use astra_prepare_button_defaults() * @param array $defaults Button default configs. * @param string $index builder button component index. * @see astra_prepare_button_defaults() * * @return array */ function prepare_button_defaults( $defaults, $index ) { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_prepare_button_defaults()' ); return astra_prepare_button_defaults( $defaults, absint( $index ) ); } /** * Deprecating prepare_html_defaults function. * * Default configurations for builder HTML components. * * @since 3.7.4 * @deprecated prepare_html_defaults() Use astra_prepare_html_defaults() * @param array $defaults HTML default configs. * @param string $index builder HTML component index. * @see astra_prepare_html_defaults() * * @return array */ function prepare_html_defaults( $defaults, $index ) { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_prepare_html_defaults()' ); return astra_prepare_html_defaults( $defaults, absint( $index ) ); } /** * Deprecating prepare_social_icon_defaults function. * * Default configurations for builder Social Icon components. * * @since 3.7.4 * @deprecated prepare_social_icon_defaults() Use astra_prepare_social_icon_defaults() * @param array $defaults Social Icon default configs. * @param string $index builder Social Icon component index. * @see astra_prepare_social_icon_defaults() * * @return array */ function prepare_social_icon_defaults( $defaults, $index ) { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_prepare_social_icon_defaults()' ); return astra_prepare_social_icon_defaults( $defaults, absint( $index ) ); } /** * Deprecating prepare_widget_defaults function. * * Default configurations for builder Widget components. * * @since 3.7.4 * @deprecated prepare_widget_defaults() Use astra_prepare_widget_defaults() * @param array $defaults Widget default configs. * @param string $index builder Widget component index. * @see astra_prepare_widget_defaults() * * @return array */ function prepare_widget_defaults( $defaults, $index ) { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_prepare_widget_defaults()' ); return astra_prepare_widget_defaults( $defaults, absint( $index ) ); } /** * Deprecating prepare_menu_defaults function. * * Default configurations for builder Menu components. * * @since 3.7.4 * @deprecated prepare_menu_defaults() Use astra_prepare_menu_defaults() * @param array $defaults Menu default configs. * @param string $index builder Menu component index. * @see astra_prepare_menu_defaults() * * @return array */ function prepare_menu_defaults( $defaults, $index ) { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_prepare_menu_defaults()' ); return astra_prepare_menu_defaults( $defaults, absint( $index ) ); } /** * Deprecating prepare_divider_defaults function. * * Default configurations for builder Divider components. * * @since 3.7.4 * @deprecated prepare_divider_defaults() Use astra_prepare_divider_defaults() * @param array $defaults Divider default configs. * @param string $index builder Divider component index. * @see astra_prepare_divider_defaults() * * @return array */ function prepare_divider_defaults( $defaults, $index ) { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_prepare_divider_defaults()' ); return astra_prepare_divider_defaults( $defaults, absint( $index ) ); } /** * Deprecating is_astra_pagination_enabled function. * * Checking if Astra's pagination enabled. * * @since 3.7.4 * @deprecated is_astra_pagination_enabled() Use astra_check_pagination_enabled() * @see astra_check_pagination_enabled() * * @return bool true|false */ function is_astra_pagination_enabled() { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_check_pagination_enabled()' ); return astra_check_pagination_enabled(); } /** * Deprecating is_current_post_comment_enabled function. * * Checking if current post's comment enabled and comment section is open. * * @since 3.7.4 * @deprecated is_current_post_comment_enabled() Use astra_check_current_post_comment_enabled() * @see astra_check_current_post_comment_enabled() * * @return bool true|false */ function is_current_post_comment_enabled() { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_check_current_post_comment_enabled()' ); return astra_check_current_post_comment_enabled(); } /** * Deprecating ast_load_preload_local_fonts function. * * Preload Google Fonts - Feature of self-hosting font. * * @since 3.7.4 * @deprecated ast_load_preload_local_fonts() Use astra_load_preload_local_fonts() * @param string $google_font_url Google Font URL generated by customizer config. * @see astra_load_preload_local_fonts() * * @return string */ function ast_load_preload_local_fonts( $google_font_url ) { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_load_preload_local_fonts()' ); return astra_load_preload_local_fonts( $google_font_url ); } /** * Deprecating ast_get_webfont_url function. * * Getting webfont based Google font URL. * * @since 3.7.4 * @deprecated ast_get_webfont_url() Use astra_get_webfont_url() * @param string $google_font_url Google Font URL generated by customizer config. * @see astra_get_webfont_url() * * @return string */ function ast_get_webfont_url( $google_font_url ) { _deprecated_function( __FUNCTION__, '3.7.4', 'astra_get_webfont_url()' ); return astra_get_webfont_url( $google_font_url ); }