Exemple #1
0
function hocwp_in_maintenance_mode_notice()
{
    if (hocwp_in_maintenance_mode()) {
        $page = hocwp_get_current_admin_page();
        if ('hocwp_maintenance' != $page) {
            $args = array('text' => sprintf(__('Your site is running in maintenance mode, so you can go to %s and turn it off when done.', 'hocwp-theme'), '<a href="' . admin_url('tools.php?page=hocwp_maintenance') . '">' . __('setting page', 'hocwp-theme') . '</a>'));
            hocwp_admin_notice($args);
        }
    }
}
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');
        }
    }
}
    }
    return $commentdata;
}
add_filter('preprocess_comment', 'hocwp_setup_theme_preprocess_comment', 1);
function hocwp_setup_theme_enable_session($use)
{
    if (!is_admin()) {
        $disable_captcha_user = hocwp_user_not_use_comment_form_captcha();
        if (hocwp_use_comment_form_captcha() && (!$disable_captcha_user || $disable_captcha_user && !is_user_logged_in())) {
            $use = true;
        }
    }
    return $use;
}
add_filter('hocwp_use_session', 'hocwp_setup_theme_enable_session');
$maintenance_mode = hocwp_in_maintenance_mode();
function hocwp_setup_theme_in_maintenance_mode_notice()
{
    hocwp_in_maintenance_mode_notice();
}
function hocwp_setup_theme_maintenance_head()
{
    $args = hocwp_maintenance_mode_settings();
    $background = hocwp_get_value_by_key($args, 'background');
    $background = hocwp_sanitize_media_value($background);
    $background = $background['url'];
    $css = '';
    if (!empty($background)) {
        $css .= hocwp_build_css_rule(array('.hocwp-maintenance'), array('background-image' => 'url("' . $background . '")'));
    }
    if (!empty($css)) {
function hocwp_theme_maintenance_mode()
{
    if (!is_admin() && hocwp_in_maintenance_mode()) {
        if (!hocwp_maintenance_mode_exclude_condition()) {
            $charset = get_bloginfo('charset') ? get_bloginfo('charset') : 'UTF-8';
            $protocol = !empty($_SERVER['SERVER_PROTOCOL']) && in_array($_SERVER['SERVER_PROTOCOL'], array('HTTP/1.1', 'HTTP/1.0')) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
            $status_code = (int) apply_filters('hocwp_maintenance_mode_status_code', 503);
            nocache_headers();
            ob_start();
            header("Content-type: text/html; charset={$charset}");
            header("{$protocol} {$status_code} Service Unavailable", true, $status_code);
            get_template_part('inc/views/maintenance');
            ob_flush();
            exit;
        }
    }
}