/** * Returns the dynamic CSS. * If possible, it also caches the CSS using WordPress transients * * @return string the dynamically-generated CSS. */ function avada_dynamic_css_cached() { /** * Get the page ID */ $c_pageID = Avada()->dynamic_css->page_id(); /** * do we have WP_DEBUG set to true? * If yes, then do not cache. */ $cache = defined('WP_DEBUG') && WP_DEBUG ? false : true; /** * If the dynamic_css_db_caching option is not set * or set to off, then do not cache. */ $cache = $cache && (null == Avada()->settings->get('dynamic_css_db_caching') || !Avada()->settings->get('dynamic_css_db_caching')) ? false : $cache; /** * If we're compiling to file, then do not use transients for caching. */ /** * Check if we're using file mode or inline mode. * This simply checks the dynamic_css_compiler options. */ $mode = Avada_Dynamic_CSS::$mode; /** * ALWAYS use 'inline' mode when in the customizer. */ global $wp_customize; if ($wp_customize) { $mode = 'inline'; } $cache = $cache && 'file' == $mode ? false : $cache; if ($cache) { /** * Build the transient name */ $transient_name = $c_pageID ? 'avada_dynamic_css_' . $c_pageID : 'avada_dynamic_css_global'; /** * Check if the dynamic CSS needs updating * If it does, then calculate the CSS and then update the transient. */ if (Avada_Dynamic_CSS::needs_update()) { /** * Calculate the dynamic CSS */ $dynamic_css = avada_dynamic_css_parser(avada_dynamic_css_array()); /** * Append the user-entered dynamic CSS */ $dynamic_css .= Avada()->settings->get('custom_css'); /** * Set the transient for an hour */ set_transient($transient_name, $dynamic_css, 60 * 60); } else { /** * Check if the transient exists. * If it does not exist, then generate the CSS and update the transient. */ if (false === ($dynamic_css = get_transient($transient_name))) { /** * Calculate the dynamic CSS */ $dynamic_css = avada_dynamic_css_parser(avada_dynamic_css_array()); /** * Append the user-entered dynamic CSS */ $dynamic_css .= Avada()->settings->get('custom_css'); /** * Set the transient for an hour */ set_transient($transient_name, $dynamic_css, 60 * 60); } } } else { /** * Calculate the dynamic CSS */ $dynamic_css = avada_dynamic_css_parser(avada_dynamic_css_array()); /** * Append the user-entered dynamic CSS */ $dynamic_css .= Avada()->settings->get('custom_css'); } return $dynamic_css; }
/** * Determine if we're using file mode or inline mode. * * @return string file/inline */ public static function set_mode() { /** * Check if we're using file mode or inline mode. * This simply checks the dynamic_css_compiler options. */ $mode = Avada()->settings->get('dynamic_css_compiler') ? 'file' : 'inline'; //var_dump('first-mode:'.$mode); //var_dump(self::needs_update()); /** * Additional checks for file mode. */ if ('file' == $mode && self::needs_update()) { /** * Only allow processing 1 file every 5 seconds. */ $current_time = (int) time(); $last_time = (int) get_option('avada_dynamic_css_time'); //var_dump('current-time:' . ( $current_time - $last_time )); if (5 <= $current_time - $last_time) { //var_dump('inside the clt'); /** * If it's been more than 5 seconds since we last compiled a file * then attempt to write to the file. * If the file-write succeeds then set mode to 'file'. * If the file-write fails then set mode to 'inline'. */ $mode = self::can_write() && self::make_css() ? 'file' : 'inline'; /** * If the file exists then set mode to 'file' * If it does not exist then set mode to 'inline'. */ if ('file' == $mode) { $mode = file_exists(self::file('path')) ? 'file' : 'inline'; } } else { /** * It's been less than 5 seconds since we last compiled a CSS file * In order to prevent server meltdowns on weak servers we'll use inline mode instead. */ $mode = 'inline'; } } //var_dump('second-mode:'.$mode); self::$mode = $mode; }
/** * Determine if we're using file mode or inline mode. * * @return string file/inline */ public static function set_mode() { // Check if we're using file mode or inline mode. // This simply checks the dynamic_css_compiler options. $mode = Avada()->settings->get('dynamic_css_compiler') ? 'file' : 'inline'; // ALWAYS use 'inline' mode when in the customizer. global $wp_customize; if ($wp_customize) { return 'inline'; } // Additional checks for file mode. if ('file' == $mode && self::needs_update()) { // Only allow processing 1 file every 5 seconds. $current_time = (int) time(); $last_time = (int) get_option('avada_dynamic_css_time'); if (5 <= $current_time - $last_time) { // If it's been more than 5 seconds since we last compiled a file // then attempt to write to the file. // If the file-write succeeds then set mode to 'file'. // If the file-write fails then set mode to 'inline'. $mode = self::can_write() && self::make_css() ? 'file' : 'inline'; // If the file exists then set mode to 'file' // If it does not exist then set mode to 'inline'. if ('file' == $mode) { $mode = file_exists(self::file('path')) ? 'file' : 'inline'; } } else { // It's been less than 5 seconds since we last compiled a CSS file // In order to prevent server meltdowns on weak servers we'll use inline mode instead. $mode = 'inline'; } } self::$mode = $mode; }