array( 'width' => 1600, 'height' => 9999, 'crop' => false, 'label' => esc_html__( 'Featured', 'primer' ), ), 'primer-hero' => array( 'width' => 2400, 'height' => 1300, 'crop' => array( 'center', 'center' ), 'label' => esc_html__( 'Hero', 'primer' ), ), ) ); foreach ( $primer_image_sizes as $name => &$args ) { if ( empty( $name ) || empty( $args['width'] ) || empty( $args['height'] ) ) { unset( $primer_image_sizes[ $name ] ); continue; } $args['crop'] = ! empty( $args['crop'] ) ? $args['crop'] : false; $args['label'] = ! empty( $args['label'] ) ? $args['label'] : ucwords( str_replace( array( '-', '_' ), ' ', $name ) ); add_image_size( sanitize_key( $name ), absint( $args['width'] ), absint( $args['height'] ), $args['crop'] ); } if ( $primer_image_sizes ) { add_filter( 'image_size_names_choose', 'primer_image_size_names_choose' ); } /** * Enable support for Automatic Feed Links. * * @link https://developer.wordpress.org/reference/functions/add_theme_support/#feed-links * @since 1.0.0 */ add_theme_support( 'automatic-feed-links' ); /** * Enable support for plugins and themes to manage the document title tag. * * @link https://developer.wordpress.org/reference/functions/add_theme_support/#title-tag * @since 1.0.0 */ add_theme_support( 'title-tag' ); /** * Enable support for Post Thumbnails on posts and pages. * * @link https://developer.wordpress.org/reference/functions/add_theme_support/#post-thumbnails * @since 1.0.0 */ add_theme_support( 'post-thumbnails' ); /** * Enable support for customizer selective refresh. * * @link https://developer.wordpress.org/reference/functions/add_theme_support/#customize-selective-refresh-widgets * @since 1.0.0 */ add_theme_support( 'customize-selective-refresh-widgets' ); /** * Register custom Custom Navigation Menus. * * @link https://developer.wordpress.org/reference/functions/register_nav_menus/ * @since 1.0.0 */ register_nav_menus( /** * Filter registered nav menus. * * @since 1.0.0 * * @var array */ (array) apply_filters( 'primer_nav_menus', array( 'primary' => esc_html__( 'Primary Menu', 'primer' ), 'social' => esc_html__( 'Social Menu', 'primer' ), 'footer' => esc_html__( 'Footer Menu', 'primer' ), ) ) ); /** * Enable support for HTML5 markup. * * @link https://codex.wordpress.org/Function_Reference/add_theme_support#HTML5 * @since 1.0.0 */ add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', ) ); /** * Enable support for Post Formats. * * @link https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Formats * @since 1.0.0 */ add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', ) ); } add_action( 'after_setup_theme', 'primer_setup' ); /** * Register image size labels. * * @filter image_size_names_choose * @since 1.0.0 * * @param array $size_names Array of image sizes and their names. * * @return array */ function primer_image_size_names_choose( $size_names ) { global $primer_image_sizes; $labels = array_combine( array_keys( $primer_image_sizes ), wp_list_pluck( $primer_image_sizes, 'label' ) ); return array_merge( $size_names, $labels ); } /** * Sets the content width in pixels, based on the theme layout. * * Priority 0 to make it available to lower priority callbacks. * * @action after_setup_theme * @global int $content_width * @since 1.0.0 */ function primer_content_width() { $layout = primer_get_layout(); $content_width = ( 'one-column-wide' === $layout ) ? 1068 : 688; /** * Filter the content width in pixels. * * @since 1.0.0 * * @param string $layout * * @var int */ $GLOBALS['content_width'] = (int) apply_filters( 'primer_content_width', $content_width, $layout ); } add_action( 'after_setup_theme', 'primer_content_width', 0 ); /** * Enable support for custom editor style. * * @link https://developer.wordpress.org/reference/functions/add_editor_style/ * @since 1.0.0 */ add_action( 'admin_init', 'add_editor_style', 10, 0 ); /** * Register sidebar areas. * * @link http://codex.wordpress.org/Function_Reference/register_sidebar * @since 1.0.0 */ function primer_register_sidebars() { /** * Filter registered sidebars areas. * * @since 1.0.0 * * @var array */ $sidebars = (array) apply_filters( 'primer_sidebars', array( 'sidebar-1' => array( 'name' => esc_html__( 'Sidebar', 'primer' ), 'description' => esc_html__( 'The primary sidebar appears alongside the content of every page, post, archive, and search template.', 'primer' ), 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ), 'sidebar-2' => array( 'name' => esc_html__( 'Secondary Sidebar', 'primer' ), 'description' => esc_html__( 'The secondary sidebar will only appear when you have selected a three-column layout.', 'primer' ), 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ), 'footer-1' => array( 'name' => esc_html__( 'Footer 1', 'primer' ), 'description' => esc_html__( 'This sidebar is the first column of the footer widget area.', 'primer' ), 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ), 'footer-2' => array( 'name' => esc_html__( 'Footer 2', 'primer' ), 'description' => esc_html__( 'This sidebar is the second column of the footer widget area.', 'primer' ), 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ), 'footer-3' => array( 'name' => esc_html__( 'Footer 3', 'primer' ), 'description' => esc_html__( 'This sidebar is the third column of the footer widget area.', 'primer' ), 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ), 'hero' => array( 'name' => esc_html__( 'Hero', 'primer' ), 'description' => esc_html__( 'Hero widgets appear over the header image on the front page.', 'primer' ), 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ), ) ); foreach ( $sidebars as $id => $args ) { register_sidebar( array_merge( array( 'id' => $id ), $args ) ); } } add_action( 'widgets_init', 'primer_register_sidebars' ); /** * Register Primer widgets. * * @link http://codex.wordpress.org/Function_Reference/register_widget * @since 1.6.0 */ function primer_register_widgets() { require_once get_template_directory() . '/inc/hero-text-widget.php'; register_widget( 'Primer_Hero_Text_Widget' ); } add_action( 'widgets_init', 'primer_register_widgets' ); /** * Enqueue theme scripts and styles. * * @link https://codex.wordpress.org/Function_Reference/wp_enqueue_style * @link https://codex.wordpress.org/Function_Reference/wp_enqueue_script * @since 1.0.0 */ function primer_scripts() { $stylesheet = get_stylesheet(); $suffix = SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style( $stylesheet, get_stylesheet_uri(), false, defined( 'PRIMER_CHILD_VERSION' ) ? PRIMER_CHILD_VERSION : PRIMER_VERSION ); wp_style_add_data( $stylesheet, 'rtl', 'replace' ); $nav_dependencies = ( is_front_page() && has_header_video() ) ? array( 'jquery', 'wp-custom-header' ) : array( 'jquery' ); wp_enqueue_script( 'primer-navigation', get_template_directory_uri() . "/assets/js/navigation{$suffix}.js", $nav_dependencies, PRIMER_VERSION, true ); wp_enqueue_script( 'primer-skip-link-focus-fix', get_template_directory_uri() . "/assets/js/skip-link-focus-fix{$suffix}.js", array(), PRIMER_VERSION, true ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } if ( primer_has_hero_image() ) { $css = sprintf( SCRIPT_DEBUG ? '%s { background-image: url(%s); }' : '%s{background-image:url(%s);}', primer_get_hero_image_selector(), esc_url( primer_get_hero_image() ) ); wp_add_inline_style( $stylesheet, $css ); } } add_action( 'wp_enqueue_scripts', 'primer_scripts' ); /** * Sets the authordata global when viewing an author archive. * * This provides backwards compatibility with * http://core.trac.wordpress.org/changeset/25574 * * It removes the need to call `the_post()` and `rewind_posts()` * in an author template to print information about the author. * * @action wp * @global WP_Query $wp_query * @global WP_User $authordata * @since 1.0.0 */ function primer_setup_author() { global $wp_query, $authordata; if ( $wp_query->is_author() && isset( $wp_query->post ) ) { $authordata = get_userdata( $wp_query->post->post_author ); // override ok. } } add_action( 'wp', 'primer_setup_author' ); /** * Reset the transient for the active categories check. * * @action create_category * @action edit_category * @action delete_category * @action save_post * @see primer_has_active_categories() * @since 1.0.0 */ function primer_has_active_categories_reset() { delete_transient( 'primer_has_active_categories' ); } add_action( 'create_category', 'primer_has_active_categories_reset' ); add_action( 'edit_category', 'primer_has_active_categories_reset' ); add_action( 'delete_category', 'primer_has_active_categories_reset' ); add_action( 'save_post', 'primer_has_active_categories_reset' );