예제 #1
0
function hocwp_load_jquery_from_cdn()
{
    if (!is_admin()) {
        $use = hocwp_use_jquery_cdn();
        if ($use) {
            global $wp_version, $wp_scripts;
            $handle = version_compare($wp_version, '3.6-alpha1', '>=') ? 'jquery-core' : 'jquery';
            $enqueued = wp_script_is($handle);
            wp_enqueue_script($handle);
            $version = '';
            $jquery_url = '';
            $google_not_exists = array('1.12.3');
            if (is_a($wp_scripts, 'WP_Scripts')) {
                $registered = $wp_scripts->registered;
                if (isset($registered[$handle])) {
                    $version = $registered[$handle]->ver;
                    if (in_array($version, $google_not_exists)) {
                        $jquery_url = '//code.jquery.com/jquery-' . $version . '.min.js';
                    }
                }
            }
            if (empty($version)) {
                $version = HOCWP_JQUERY_LATEST_VERSION;
            }
            if (empty($jquery_url)) {
                $jquery_url = '//ajax.googleapis.com/ajax/libs/jquery/' . $version . '/jquery.min.js';
            }
            wp_dequeue_script($handle);
            wp_deregister_script($handle);
            wp_register_script($handle, $jquery_url);
            if ($enqueued) {
                wp_enqueue_script($handle);
                add_action('hocwp_before_wp_head', 'hocwp_jquery_google_cdn_fallback');
            }
        }
    }
}
예제 #2
0
function hocwp_setup_theme_scripts()
{
    do_action('hocwp_enqueue_scripts');
    if (hocwp_use_jquery_cdn()) {
        hocwp_load_jquery_from_cdn();
    }
    hocwp_theme_register_lib_superfish();
    hocwp_theme_register_lib_bootstrap();
    hocwp_theme_register_lib_font_awesome();
    hocwp_theme_register_core_style_and_script();
    if (hocwp_theme_sticky_last_widget()) {
        hocwp_theme_register_lib_sticky();
    }
    $localize_object = array('expand' => '<span class="screen-reader-text">' . esc_html__('expand child menu', 'hocwp-theme') . '</span>', 'collapse' => '<span class="screen-reader-text">' . esc_html__('collapse child menu', 'hocwp-theme') . '</span>');
    $localize_object = wp_parse_args($localize_object, hocwp_theme_default_script_localize_object());
    $use = hocwp_use_core_style();
    $superfish = hocwp_use_superfish_menu();
    if (hocwp_is_debugging()) {
        wp_localize_script('hocwp', 'hocwp', $localize_object);
        wp_register_style('hocwp-front-end-style', get_template_directory_uri() . '/hocwp/css/hocwp-front-end' . HOCWP_CSS_SUFFIX, array('hocwp-style'));
        wp_register_script('hocwp-front-end', get_template_directory_uri() . '/hocwp/js/hocwp-front-end' . HOCWP_JS_SUFFIX, array('hocwp'), false, true);
        $style_deps = array('bootstrap-style', 'font-awesome-style', 'superfish-style', 'hocwp-front-end-style');
        $script_deps = array('superfish', 'bootstrap', 'hocwp-front-end');
        if (!$use) {
            unset($style_deps[array_search('hocwp-front-end-style', $style_deps)]);
        }
        if (!$superfish) {
            unset($style_deps[array_search('superfish-style', $style_deps)]);
            unset($script_deps[array_search('superfish', $script_deps)]);
        }
        wp_register_style('hocwp-custom-font-style', get_template_directory_uri() . '/css/hocwp-custom-font' . HOCWP_CSS_SUFFIX);
        $style_deps[] = 'hocwp-custom-font-style';
        wp_register_style('hocwp-custom-front-end-style', get_template_directory_uri() . '/css/hocwp-custom-front-end' . HOCWP_CSS_SUFFIX, $style_deps);
        wp_register_script('hocwp-custom-front-end', get_template_directory_uri() . '/js/hocwp-custom-front-end' . HOCWP_JS_SUFFIX, $script_deps, false, true);
    } else {
        $style_deps = array('bootstrap-style', 'font-awesome-style', 'superfish-style');
        $script_deps = array('superfish', 'bootstrap');
        if (!$superfish) {
            unset($style_deps[array_search('superfish-style', $style_deps)]);
            unset($script_deps[array_search('superfish', $script_deps)]);
        }
        wp_register_style('hocwp-custom-front-end-style', get_template_directory_uri() . '/css/hocwp-custom-front-end' . HOCWP_CSS_SUFFIX, $style_deps, HOCWP_THEME_VERSION);
        wp_register_script('hocwp-custom-front-end', get_template_directory_uri() . '/js/hocwp-custom-front-end' . HOCWP_JS_SUFFIX, $script_deps, HOCWP_THEME_VERSION, true);
        wp_localize_script('hocwp-custom-front-end', 'hocwp', $localize_object);
    }
    if (!hocwp_in_maintenance_mode()) {
        wp_enqueue_style('hocwp-custom-front-end-style');
        wp_enqueue_script('hocwp-custom-front-end');
    }
    if (is_singular()) {
        $post_id = get_the_ID();
        if (comments_open($post_id) && (bool) get_option('thread_comments')) {
            wp_enqueue_script('comment-reply');
        }
    }
}