Yuzu Theme
from meowapps.com
This commit is contained in:
367
functions.php
Normal file
367
functions.php
Normal file
@@ -0,0 +1,367 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
/**
|
||||
* Yuzu functions and definitions
|
||||
*
|
||||
* @link https://developer.wordpress.org/themes/basics/theme-functions/
|
||||
*
|
||||
* @package Yuzu
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'yuzu_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 yuzu_setup() {
|
||||
/*
|
||||
* Make theme available for translation.
|
||||
* Translations can be filed in the /languages/ directory.
|
||||
* If you're building a theme based on Yuzu, use a find and replace
|
||||
* to change 'yuzu' to the name of your theme in all the template files.
|
||||
*/
|
||||
load_theme_textdomain( 'yuzu', 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' );
|
||||
|
||||
/*
|
||||
* Gutenberg Align wide support.
|
||||
*/
|
||||
add_theme_support( 'align-wide' );
|
||||
|
||||
/*
|
||||
* 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(
|
||||
'menu-1' => esc_html__( 'Primary', 'yuzu' ),
|
||||
) );
|
||||
|
||||
/*
|
||||
* 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',
|
||||
) );
|
||||
|
||||
// Set up the WordPress core custom background feature.
|
||||
add_theme_support( 'custom-background', apply_filters( 'yuzu_custom_background_args', array(
|
||||
'default-color' => 'ffffff',
|
||||
'default-image' => '',
|
||||
) ) );
|
||||
|
||||
// Add theme support for selective refresh for widgets.
|
||||
add_theme_support( 'customize-selective-refresh-widgets' );
|
||||
|
||||
/**
|
||||
* Add support for core custom logo.
|
||||
*
|
||||
* @link https://codex.wordpress.org/Theme_Logo
|
||||
*/
|
||||
add_theme_support( 'custom-logo', array(
|
||||
'height' => 120,
|
||||
'flex-width' => true,
|
||||
'flex-height' => true,
|
||||
) );
|
||||
}
|
||||
endif;
|
||||
add_action( 'after_setup_theme', 'yuzu_setup' );
|
||||
|
||||
/**
|
||||
* 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 yuzu_content_width() {
|
||||
// This variable is intended to be overruled from themes.
|
||||
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
|
||||
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||
$GLOBALS['content_width'] = apply_filters( 'yuzu_content_width', 640 );
|
||||
}
|
||||
add_action( 'after_setup_theme', 'yuzu_content_width', 0 );
|
||||
|
||||
/**
|
||||
* Register widget area.
|
||||
*
|
||||
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
|
||||
*/
|
||||
function yuzu_widgets_init() {
|
||||
register_sidebar( array(
|
||||
'name' => esc_html__( 'Footer · Left', 'yuzu' ),
|
||||
'id' => 'footer-left',
|
||||
'description' => esc_html__( 'Add widgets here.', 'yuzu' ),
|
||||
'before_widget' => '<section id="%1$s" class="widget %2$s">',
|
||||
'after_widget' => '</section>',
|
||||
'before_title' => '<h3 class="widget-title">',
|
||||
'after_title' => '</h3>',
|
||||
) );
|
||||
register_sidebar( array(
|
||||
'name' => esc_html__( 'Footer · Middle', 'yuzu' ),
|
||||
'id' => 'footer-middle',
|
||||
'description' => esc_html__( 'Add widgets here.', 'yuzu' ),
|
||||
'before_widget' => '<section id="%1$s" class="widget %2$s">',
|
||||
'after_widget' => '</section>',
|
||||
'before_title' => '<h3 class="widget-title">',
|
||||
'after_title' => '</h3>',
|
||||
) );
|
||||
register_sidebar( array(
|
||||
'name' => esc_html__( 'Footer · Right', 'yuzu' ),
|
||||
'id' => 'footer-right',
|
||||
'description' => esc_html__( 'Add widgets here.', 'yuzu' ),
|
||||
'before_widget' => '<section id="%1$s" class="widget %2$s">',
|
||||
'after_widget' => '</section>',
|
||||
'before_title' => '<h3 class="widget-title">',
|
||||
'after_title' => '</h3>',
|
||||
) );
|
||||
}
|
||||
add_action( 'widgets_init', 'yuzu_widgets_init' );
|
||||
|
||||
/**
|
||||
* Enqueue scripts and styles.
|
||||
*/
|
||||
function yuzu_scripts() {
|
||||
$ver_num = mt_rand();
|
||||
|
||||
wp_enqueue_style( 'yuzu-custom-properties', get_template_directory_uri() . '/assets/css/custom-properties.css', array(), $ver_num );
|
||||
|
||||
wp_enqueue_style( 'yuzu-style', get_stylesheet_uri(), array(), $ver_num );
|
||||
|
||||
wp_enqueue_script( 'jquery' );
|
||||
|
||||
wp_enqueue_script( 'main-js', get_template_directory_uri() . '/assets/js/main.js', array('jquery'), $ver_num, true );
|
||||
|
||||
$dataToBePassed = array(
|
||||
'enable_posts_height_equalizer' => get_theme_mod('enable_posts_height_equalizer', true),
|
||||
'test' => 'test'
|
||||
);
|
||||
wp_localize_script( 'main-js', 'php_vars', $dataToBePassed );
|
||||
|
||||
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
|
||||
wp_enqueue_script( 'comment-reply' );
|
||||
}
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'yuzu_scripts' );
|
||||
|
||||
/**
|
||||
* Registers an editor stylesheet for the theme.
|
||||
*/
|
||||
function yuzu_add_editor_styles() {
|
||||
add_editor_style( 'editor-style.css' );
|
||||
}
|
||||
add_action( 'admin_init', 'yuzu_add_editor_styles' );
|
||||
|
||||
function legit_block_editor_styles() {
|
||||
wp_enqueue_style( 'legit-editor-styles', get_theme_file_uri( '/assets/css/editor-style.css' ), false, '1.0', 'all' );
|
||||
}
|
||||
add_action( 'enqueue_block_editor_assets', 'legit_block_editor_styles' );
|
||||
|
||||
/**
|
||||
* Apply Color Scheme Class
|
||||
*/
|
||||
add_filter( 'body_class', 'apply_theme_color_scheme');
|
||||
function apply_theme_color_scheme( $classes ) {
|
||||
$classes[] = get_theme_mod('color_scheme', 'light') . '-theme';
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce excerpt length
|
||||
*/
|
||||
add_filter( 'excerpt_length', function($length) {
|
||||
return 25;
|
||||
} );
|
||||
|
||||
/**
|
||||
* Load Meow Blocks Output
|
||||
*/
|
||||
require get_template_directory() . '/inc/meow-blocks-output.php';
|
||||
|
||||
|
||||
/**
|
||||
* Implement the Custom Header feature.
|
||||
*/
|
||||
require get_template_directory() . '/inc/custom-header.php';
|
||||
|
||||
/**
|
||||
* Custom template tags for this theme.
|
||||
*/
|
||||
require get_template_directory() . '/inc/template-tags.php';
|
||||
|
||||
/**
|
||||
* Functions which enhance the theme by hooking into WordPress.
|
||||
*/
|
||||
require get_template_directory() . '/inc/template-functions.php';
|
||||
|
||||
/**
|
||||
* Customizer additions.
|
||||
*/
|
||||
require get_template_directory() . '/inc/custom-controls.php';
|
||||
|
||||
/**
|
||||
* Customizer additions.
|
||||
*/
|
||||
require get_template_directory() . '/inc/customizer.php';
|
||||
|
||||
/**
|
||||
* Apply Customizer Colors.
|
||||
*/
|
||||
require get_template_directory() . '/inc/apply-colors.php';
|
||||
|
||||
/**
|
||||
* Load Jetpack compatibility file.
|
||||
*/
|
||||
if ( defined( 'JETPACK__VERSION' ) ) {
|
||||
require get_template_directory() . '/inc/jetpack.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom comment template
|
||||
*/
|
||||
function yuzu_comment_template($comment, $args, $depth) {
|
||||
$GLOBALS['comment'] = $comment; ?>
|
||||
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
|
||||
<div id="comment-<?php comment_ID(); ?>">
|
||||
<div class='comment-header'>
|
||||
<div class='comment-author-profil-picture'>
|
||||
<?php echo get_avatar($comment,$size='48'); ?>
|
||||
</div>
|
||||
<div class="comment-meta">
|
||||
<div class="author-name"><?php echo get_comment_author_link(); ?></div>
|
||||
<div class="posted-on"><?php echo get_comment_date(); ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='comment-content'>
|
||||
<?php if ($comment->comment_approved == '0') : ?>
|
||||
<em><?php _e('Your comment is awaiting moderation.', 'yuzu') ?></em>
|
||||
<br />
|
||||
<?php endif; ?>
|
||||
<?php comment_text() ?>
|
||||
</div>
|
||||
<div class='reply-link'>
|
||||
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Improve search results to include collections and attachments.
|
||||
*/
|
||||
function attachment_search( $query ) {
|
||||
if ( $query->is_search ) {
|
||||
$query->set( 'post_type', array( 'post', 'attachment', 'meow_collection' ) );
|
||||
$query->set( 'post_status', array( 'publish', 'inherit' ) );
|
||||
$query->set( 'posts_per_page', '-1');
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
add_filter( 'pre_get_posts', 'attachment_search' );
|
||||
|
||||
|
||||
require_once( get_template_directory() . '/class-tgm-plugin-activation.php');
|
||||
|
||||
add_action( 'tgmpa_register', 'yuzu_register_required_plugins' );
|
||||
|
||||
/**
|
||||
* Register the required plugins for this theme.
|
||||
*
|
||||
* <snip />
|
||||
*
|
||||
* This function is hooked into tgmpa_init, which is fired within the
|
||||
* TGM_Plugin_Activation class constructor.
|
||||
*/
|
||||
function yuzu_register_required_plugins() {
|
||||
/*
|
||||
* Array of plugin arrays. Required keys are name and slug.
|
||||
* If the source is NOT from the .org repo, then source is also required.
|
||||
*/
|
||||
$plugins = array(
|
||||
// This is an example of how to include a plugin from the WordPress Plugin Repository.
|
||||
array(
|
||||
'name' => 'Photography Core',
|
||||
'slug' => 'photography-core',
|
||||
'required' => false,
|
||||
),
|
||||
array(
|
||||
'name' => 'WP/LR Sync',
|
||||
'slug' => 'wplr-sync',
|
||||
'required' => false,
|
||||
),
|
||||
array(
|
||||
'name' => 'Meow Gallery',
|
||||
'slug' => 'meow-gallery',
|
||||
'is_callable' => array( 'Meow_Gallery_Core', 'installed' ),
|
||||
'required' => false,
|
||||
),
|
||||
array(
|
||||
'name' => 'Meow Lightbox',
|
||||
'slug' => 'meow-lightbox',
|
||||
'is_callable' => array( 'Meow_Lightbox_Core', 'installed' ),
|
||||
'required' => false,
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
* Array of configuration settings. Amend each line as needed.
|
||||
*
|
||||
* TGMPA will start providing localized text strings soon. If you already have translations of our standard
|
||||
* strings available, please help us make TGMPA even better by giving us access to these translations or by
|
||||
* sending in a pull-request with .po file(s) with the translations.
|
||||
*
|
||||
* Only uncomment the strings in the config array if you want to customize the strings.
|
||||
*/
|
||||
$config = array(
|
||||
'id' => 'tgmpa', // Unique ID for hashing notices for multiple instances of TGMPA.
|
||||
'default_path' => '', // Default absolute path to bundled plugins.
|
||||
'menu' => 'tgmpa-install-plugins', // Menu slug.
|
||||
'parent_slug' => 'themes.php', // Parent menu slug.
|
||||
'capability' => 'edit_theme_options', // Capability needed to view plugin install page, should be a capability associated with the parent menu used.
|
||||
'has_notices' => true, // Show admin notices or not.
|
||||
'dismissable' => true, // If false, a user cannot dismiss the nag message.
|
||||
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
|
||||
'is_automatic' => false, // Automatically activate plugins after installation or not.
|
||||
'message' => '', // Message to output right before the plugins table.
|
||||
);
|
||||
|
||||
tgmpa( $plugins, $config );
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
MEOW APPS LICENSE
|
||||
*/
|
||||
|
||||
global $meowapps_theme_version;
|
||||
$meowapps_theme_version = '0.1.0';
|
||||
|
||||
function prefix_theme_updater() {
|
||||
require( get_template_directory() . '/updater/yuzu-updater.php' );
|
||||
}
|
||||
add_action( 'after_setup_theme', 'prefix_theme_updater' );
|
||||
Reference in New Issue
Block a user