<?php
/**
 * Pix主题 - 基础函数
 * 
 * 主题初始化、菜单、图像尺寸等基础功能
 * 
 * @package pix
 * @author Fuzzz
 * @version 1.0.4
 */

function pix_setup() {

	//load_theme_textdomain( 'pix', get_template_directory() . '/languages' );

	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'title-tag' );

	//注册菜单
	register_nav_menus(
		array(
            'top' => esc_html__( '顶部主导航', 'pix' ),
			'top_sub' => esc_html__( '顶部副导航', 'pix' ),
			'left' => esc_html__( '侧边导航(需侧边导航模式下)', 'pix' ),
		)
	);

	add_theme_support(
		'html5',
		array(
			'search-form',
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
			'style',
			'script',
		)
	);

	// Add theme support for selective refresh for widgets.
	add_theme_support( 'customize-selective-refresh-widgets' );

}
add_action( 'after_setup_theme', 'pix_setup' );

/**
 * 注册小工具
 */
function pix_widgets_init() {
	register_sidebar(
		array(
			'name'          => esc_html__( '博客左侧', 'pix' ),
			'id'            => 'blog-left',
			'description'   => esc_html__( '博客页面左侧小工具区域', 'pix' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s box wid-p wid-box">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);

	register_sidebar(
		array(
			'name'          => esc_html__( '博客右侧', 'pix' ),
			'id'            => 'blog-right',
			'description'   => esc_html__( '博客页面右侧小工具区域', 'pix' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s box wid-p wid-box">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);

	register_sidebar(
		array(
			'name'          => esc_html__( '圈子右侧', 'pix' ),
			'id'            => 'moment-right',
			'description'   => esc_html__( '圈子页面右侧小工具区域', 'pix' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s box wid-p wid-box">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);

	register_sidebar(
		array(
			'name'          => esc_html__( '圈子左侧', 'pix' ),
			'id'            => 'moment-left',
			'description'   => esc_html__( '圈子页面左侧小工具区域', 'pix' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s box wid-p wid-box">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);

	register_sidebar(
		array(
			'name'          => esc_html__( '页面左侧小工具', 'pix' ),
			'id'            => 'page-left',
			'description'   => esc_html__( '页面左侧小工具区域', 'pix' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s box wid-p wid-box">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);

	register_sidebar(
		array(
			'name'          => esc_html__( '页面右侧小工具', 'pix' ),
			'id'            => 'page-right',
			'description'   => esc_html__( '页面右侧小工具区域', 'pix' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s box wid-p wid-box">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);

	register_sidebar(
		array(
			'name'          => esc_html__( '文章内页左侧小工具', 'pix' ),
			'id'            => 'post-left',
			'description'   => esc_html__( '文章内页左侧小工具区域', 'pix' ),	
			'before_widget' => '<section id="%1$s" class="widget %2$s box wid-p wid-box">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);

	register_sidebar(
		array(
			'name'          => esc_html__( '文章内页右侧小工具', 'pix' ),
			'id'            => 'post-right',
			'description'   => esc_html__( '文章内页右侧小工具区域', 'pix' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s box wid-p wid-box">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);

	register_sidebar(
		array(
			'name'          => esc_html__( '页脚小工具', 'pix' ),
			'id'            => 'footer-widget',
			'description'   => esc_html__( '页脚区域小工具，显示在版权信息上方', 'pix' ),
			'before_widget' => '<div id="%1$s" class="footer-widget %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h3 class="footer-widget-title">',
			'after_title'   => '</h3>',
		)
	);
}
add_action( 'widgets_init', 'pix_widgets_init' );

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function pix_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'pix_content_width', 640 );
}
add_action( 'after_setup_theme', 'pix_content_width', 0 );
