コード例 #1
0
/**
 * 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;
}
コード例 #2
0
/**
 * 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 not then we can try caching it.
     * If yes then we won't cache anything.
     */
    if (!defined('WP_DEBUG') || !WP_DEBUG) {
        /**
         * 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;
}