HEX
Server: nginx/1.16.1
System: Linux ecs-04358622 4.19.90-2107.6.0.0100.oe1.bclinux.x86_64 #1 SMP Wed Dec 1 19:59:44 CST 2021 x86_64
User: nginx (994)
PHP: 8.0.0
Disabled: NONE
Upload Files
File: /home/www/wp-content/themes/qizhou/functions.php
<?php
/**
 * Makaffo functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Makaffo
 */

if ( ! function_exists( 'makaffo_setup' ) ) :
	/**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * Note that this function is hooked into the after_setup_theme hook, which
	 * runs before the init hook. The init hook is too late for some features, such
	 * as indicating support for post thumbnails.
	 */
	function makaffo_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on _s, use a find and replace
		 * to change 'makaffo' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'makaffo', get_template_directory() . '/languages' );

		// Add default posts and comments RSS feed links to head.
		add_theme_support( 'automatic-feed-links' );

		/*
		 * Let WordPress manage the document title.
		 * By adding theme support, we declare that this theme does not use a
		 * hard-coded <title> tag in the document head, and expect WordPress to
		 * provide it for us.
		 */
		add_theme_support( 'title-tag' );
		
		/*
		 * Enable support for Post Thumbnails on posts and pages.
		 *
		 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
		 */
		add_theme_support( 'post-thumbnails' );

		// This theme uses wp_nav_menu() in one location.
		register_nav_menus( array(
			'primary' => esc_html__( 'Primary', 'makaffo' ),
		) );

		/*
		 * Switch default core markup for search form, comment form, and comments
		 * to output valid HTML5.
		 */
		add_theme_support( 'html5', array(
			'search-form',
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
		) );

		/*
		 * Enable support for Post Formats.
		 *
		 * See: https://codex.wordpress.org/Post_Formats
		 */
		add_theme_support( 'post-formats', array(
			'image',
			'video',
			'quote',
			'gallery',
			'link',
			'audio',
		) );

		/* Add image sizes */
	}
endif;
add_action( 'after_setup_theme', 'makaffo_setup' );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function makaffo_widgets_init() {
	/* Register the 'primary' sidebar. */
	register_sidebar( array(
		'name'          => esc_html__( 'Primary Sidebar', 'makaffo' ),
		'id'            => 'primary',
		'description'   => esc_html__( 'Add widgets here.', 'makaffo' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h5 class="widget-title">',
		'after_title'   => '</h5>',
	) );
	/* Repeat register_sidebar() code for additional sidebars. */
}
add_action( 'widgets_init', 'makaffo_widgets_init' );

/**
 * Enqueue scripts and styles.
 */
function makaffo_scripts() {

	/** Flaticon/Text fonts **/
    wp_enqueue_style( 'makaffo-font-icon', get_template_directory_uri().'/css/flaticon.css');
    wp_enqueue_style( 'makaffo-font-text', get_template_directory_uri().'/css/font-text.css');

	/** All frontend css files **/ 
	wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.css', array(), '4.0', 'all');

    /** Owl slider **/
	wp_enqueue_style( 'owl-slider', get_template_directory_uri().'/css/owl.carousel.min.css');
	
	/** Lightgallery Popup **/
    wp_enqueue_style( 'lightgallery', get_template_directory_uri().'/css/lightgallery.css');

	/** Theme stylesheet. **/
	$theme = wp_get_theme();
	if( is_child_theme() ) { $theme = wp_get_theme()->parent(); }
	
	wp_enqueue_style( 'makaffo-style', get_template_directory_uri() . '/style.css', array(), $theme->version );

	wp_enqueue_script( 'imagesloaded' );
	if( makaffo_get_option( 'preload' ) != false ){
		wp_enqueue_script('makaffo-royal-preloader', get_template_directory_uri()."/js/royal_preloader.min.js",array('jquery'), '1.0', true); 
	}
    wp_enqueue_script( 'makaffo-plugin-addon', get_template_directory_uri().'/js/plugin-addon.js', array('jquery'), '20180910',  true );
    wp_enqueue_script( 'makaffo-elementor', get_template_directory_uri() . '/js/elementor.js', array( 'jquery' ), '20230324', true );
	wp_enqueue_script( 'makaffo-elementor-header', get_template_directory_uri() . '/js/elementor-header.js', array('jquery'), '20230324', true );
	wp_enqueue_script( 'makaffo-scripts', get_template_directory_uri() . '/js/scripts.js', array( 'jquery' ), '20230324', true );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'makaffo_scripts' );

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/frontend/template-tags.php';

/**
 * Functions which enhance the theme by hooking into WordPress.
 */
require get_template_directory() . '/inc/frontend/template-functions.php';

/**
 * Custom Page Header for this theme.
 */
require get_template_directory() . '/inc/frontend/page-header/breadcrumbs.php';
// 引入页面头部文件
require_once get_template_directory() . '/inc/frontend/page-header/page-header.php';
// 添加Portfolio头部文件引用
require_once get_template_directory() . '/inc/frontend/page-header/portfolio-header.php';

/**
 * Functions which add more to backend.
 */
require get_template_directory() . '/inc/backend/admin-functions.php';

/**
 * Custom metabox for this theme.
 */
require get_template_directory() . '/inc/backend/meta-boxes.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/backend/customizer/customizer.php';

/**
 * Register the required plugins for this theme.
 */
require get_template_directory() . '/inc/backend/plugin-requires.php';
require get_template_directory() . '/inc/backend/importer.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/backend/color.php';

/**
 * Preloader js & css
 */
require get_template_directory() . '/inc/frontend/preloader.php';

/**
 * Elementor functions.
 */
if ( did_action( 'elementor/loaded' ) ) {
	require get_template_directory() . '/inc/backend/elementor/elementor.php';
}
require get_template_directory() . '/inc/frontend/builder.php';

/**
 * Load WooCommerce compatibility file.
 */
if ( class_exists( 'woocommerce' ) ) {
	require get_template_directory() . '/inc/woocommerce/woocommerce.php';
}

/**
 * 新文章自动使用ID作为别名
 * 作用:即使你设置固定连接结构为 %postname% ,仍旧自动生成 /%postname%.html结构的链接
 */
add_action( 'save_post', 'using_id_as_slug', 10, 2 );
function using_id_as_slug($post_id, $post){
	global $post_type;
	if($post_type=='post'){ //只对文章生效
		// 如果是文章的版本,不生效
		if (wp_is_post_revision($post_id))
			return false;
		// 取消挂载该函数,防止无限循环
		remove_action('save_post', 'using_id_as_slug' );
		// 使用文章ID作为文章的别名
		wp_update_post(array('ID' => $post_id, 'post_name' => $post_id ));
		// 重新挂载该函数
		add_action('save_post', 'using_id_as_slug' );
	}
}

function makaffo_favicon_setup() {
    // 获取用户上传的站点图标
    $custom_favicon = get_site_icon_url();
    
    // 如果用户未上传自定义图标,则使用主题默认图标
    if (empty($custom_favicon)) {
        $template_dir = get_template_directory_uri() . '/images/';
        
        // 输出不同尺寸的默认图标
        echo '<link rel="icon" href="' . esc_url($template_dir . 'favicon-32x32.svg') . '" sizes="32x32">';
        echo '<link rel="icon" href="' . esc_url($template_dir . 'favicon-192x192.svg') . '" sizes="192x192">';
        echo '<link rel="apple-touch-icon" href="' . esc_url($template_dir . 'favicon-180x180.svg') . '" sizes="180x180">';
        echo '<meta name="msapplication-TileImage" content="' . esc_url($template_dir . 'favicon-270x270.svg') . '">';
    }
}
add_action('wp_head', 'makaffo_favicon_setup');
/**
 * 隐藏WooCommerce产品描述标签页标题
 */
add_filter('woocommerce_product_description_heading', function() {
    return ''; // 返回空字符串以隐藏标题
});

// 添加Portfolio自定义面包屑函数
if ( ! function_exists( 'makaffo_portfolio_get_breadcrumbs' ) ) {
    function makaffo_portfolio_get_breadcrumbs() {
        $breadcrumb = '<ul class="breadcrumbs none-style">';
        
        // 首页链接
        $breadcrumb .= '<li><a class="hover" href="' . home_url() . '">' . esc_html__('Home', 'makaffo') . '</a></li>';
        
        // Portfolio归档链接
        $archive_link = '';
        if (makaffo_get_option('portfolio_archive') == 'archive_custom') {
            $archive_link = get_page_link(makaffo_get_option('archive_page_custom'));
        } else {
            $archive_link = get_post_type_archive_link('ot_portfolio');
        }
        $breadcrumb .= '<li><a class="hover" href="' . $archive_link . '">Portfolio</a></li>';
        
        // 获取当前项目的分类
        $terms = get_the_terms(get_the_ID(), 'portfolio_category');
        if ($terms && !is_wp_error($terms)) {
            $term = $terms[0];
            $breadcrumb .= '<li class="active">' . $term->name . '</li>';
        }
        
        $breadcrumb .= '</ul>';
        return $breadcrumb;
    }
}

if ( ! function_exists( 'makaffo_portfolio_breadcrumbs' ) ) {
    function makaffo_portfolio_breadcrumbs() {
        echo makaffo_portfolio_get_breadcrumbs();
    }
}
//取消 webP 格式环境检查
add_filter('plupload_default_settings', function($defaults) {
    $defaults['webp_upload_error'] = false;
    return $defaults;
}, 10, 1);

add_filter('plupload_init', function($plupload_init) {
    $plupload_init['webp_upload_error'] = false;
    return $plupload_init;
}, 10, 1);