File: /www/wwwroot/www.213n.cn/wp-content/themes/rk-blogger/wbc/common/init.php
<?php
if (!defined('WB_THEME_DIR')) {
define('WB_THEME_DIR', get_template_directory());
}
if (!defined('WB_THEME_URI')) {
define('WB_THEME_URI', get_template_directory_uri());
}
if (!defined('WBC_DIR')) {
define('WBC_DIR', get_template_directory() . '/wbc');
}
if (version_compare($GLOBALS['wp_version'], '5.5-alpha', '<')) {
require get_template_directory_uri() . '/configure/common/back-compat.php';
}
add_action('after_setup_theme', 'wbolt_setup');
add_action('init', 'wb_init');
if (!function_exists('wbolt_setup')) :
function wbolt_setup()
{
// Add default posts and comments RSS feed links to head.
add_theme_support('automatic-feed-links');
load_theme_textdomain(WB_THEMES_CODE, get_template_directory() . '/languages');
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style(get_template_directory_uri() . '/css/editor-style.css?v=' . WB_ASSETS_VER);
add_theme_support('post-thumbnails');
set_post_thumbnail_size(WB_THUMBNAIL_WIDTH, WB_THUMBNAIL_HEIGHT, false);
add_theme_support("wp-block-styles");
add_theme_support("responsive-embeds");
add_theme_support("custom-logo", array());
add_theme_support("align-wide");
add_theme_support("title-tag");
add_theme_support("custom-header", array());
add_theme_support("custom-background", array());
add_theme_support('html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
));
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(array(
'primary' => '主导航菜单',
'social' => '页脚菜单',
));
}
endif; // wbolt_setup
if (!function_exists('wb_init')) :
function wb_init()
{
add_filter('wp_footer', function ($html = "\n") {
if (wb_opt('ft_code')) {
$html .= wb_opt('ft_code') . "\n";
}
if (wb_opt('stats_code')) {
$html .= '<div style="display:none;">' . wb_opt('stats_code') . '</div>' . "\n";
}
return $html;
});
add_filter('wb_js_conf', function ($opt_js_cont = '') {
//列表自动加载
if ($mxpage = wb_opt('mxpage', 3)) {
$opt_js_cont .= ' var wb_auto_load_max = ' . $mxpage . ';';
}
//默认图片
if (wb_opt('def_img_url')) {
$opt_js_cont .= ' var _def_pic_url = "' . wb_opt('def_img_url') . '";';
}
return $opt_js_cont;
});
add_action('wp_enqueue_scripts', function () {
// 主题颜色
$theme_color_var = wb_opt('theme_color');
// 自定义样式
$custom_css = wb_opt('usr_css', '');
// css变量钩子
$css_var = apply_filters('wb_css_var', '');
if ($theme_color_var) {
$css_var .= "--wb-theme-color:" . $theme_color_var . "; --wb-theme-hover-color:" . $theme_color_var . "; ";
}
$css_var = !empty($css_var) ? ':root{' . $css_var . '}' : '';
$custom_css = $css_var . $custom_css . apply_filters('wb_custom_styles', '');
if ($custom_css || $css_var) {
wp_register_style('wb-inline', false, null, false);
wp_enqueue_style('wb-inline');
wp_add_inline_style('wb-inline', $custom_css);
}
$js_var = array(
'home_url' => home_url(),
'theme_url' => get_template_directory_uri(),
'ajax_url' => admin_url('/admin-ajax.php'),
'theme_name' => WB_THEMES_CODE, 'assets_ver' => WB_ASSETS_VER
);
$js_var['_wp_uid'] = get_current_user_id();
$js_var['_pid'] = get_the_ID() ? get_the_ID() : 0;
$conf_js = "var wb_base = " . json_encode($js_var) . "; " . apply_filters('wb_js_conf', '') . "\n";
wp_register_script('wb-cnf-inline', false, null, false);
wp_enqueue_script('wb-cnf-inline');
wp_add_inline_script('wb-cnf-inline', apply_filters('wb_js_conf', $conf_js), 'before');
});
add_action('wp_head', function () {
if (is_single() || is_page()) {
wb_set_post_views(get_the_ID());
}
if ($hd_code = wb_opt('hd_code')) {
echo $hd_code . "\n";
}
});
}
endif;