Files
Bookshelf/Old/bd-murphy-author/functions.php
bdm 38cdebd0c6 Track Bookshelf WordPress theme, plugins and specs
Initial import of the bdmurphy Bookshelf work: the bd-bookshelf theme,
bd-bookshelf-plugin, bd-bookshelfhelper and bd-simpleemail plugins, plus
the specification documents, mockups and release archives.
2026-09-28 06:24:25 -07:00

158 lines
5.8 KiB
PHP

<?php
/**
* BD Murphy Bookshelf Theme Functions
*
* @package BD_Murphy
*/
if (!defined('ABSPATH')) {
exit;
}
define('BDM_VERSION', '1.5.0');
define('BDM_DIR', get_template_directory());
define('BDM_URI', get_template_directory_uri());
require_once BDM_DIR . '/inc/customizer.php';
require_once BDM_DIR . '/inc/theme-options.php';
require_once BDM_DIR . '/inc/template-tags.php';
require_once BDM_DIR . '/inc/widgets.php';
require_once BDM_DIR . '/inc/nav-menu.php';
function bdm_setup() {
load_theme_textdomain('bd-murphy', BDM_DIR . '/languages');
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'script', 'style'));
add_theme_support('automatic-feed-links');
add_theme_support('wp-block-styles');
add_editor_style('assets/editor-style.css');
add_theme_support('custom-logo', array(
'width' => 200,
'height' => 200,
'flex-width' => true,
'flex-height' => true,
));
add_theme_support('custom-header', array(
'default-image' => BDM_URI . '/assets/banner_1200x200_v3.png',
'width' => 1200,
'height' => 200,
'flex-height' => false,
));
add_theme_support('custom-background', array(
'default-color' => 'F5F0E8',
));
add_image_size('shelf-thumb', 44, 62, true);
add_image_size('blog-thumb', 100, 68, true);
add_image_size('rev-thumb', 52, 74, true);
add_image_size('book-cover', 130, 185, true);
add_image_size('book-page-cover', 220, 310, true);
add_image_size('series-card', 400, 280, true);
add_image_size('series-header', 1200, 300, true);
register_nav_menus(array(
'primary' => __('Primary Menu', 'bd-murphy'),
'footer' => __('Footer Menu', 'bd-murphy'),
));
register_sidebar(array(
'name' => __('Home Sidebar', 'bd-murphy'),
'id' => 'home-sidebar',
'description' => __('Widget area for the book shelf on the home page', 'bd-murphy'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
register_sidebar(array(
'name' => __('Footer Left', 'bd-murphy'),
'id' => 'footer-left',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
));
register_sidebar(array(
'name' => __('Footer Right', 'bd-murphy'),
'id' => 'footer-right',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
));
}
add_action('after_setup_theme', 'bdm_setup');
function bdm_enqueue_assets() {
wp_enqueue_style('bd-murphy-style', get_stylesheet_uri(), array(), BDM_VERSION);
wp_enqueue_style('bd-murphy-google-fonts', 'https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;1,400&family=Lato:wght@300;400;700&display=swap', array(), null);
wp_enqueue_script('bd-murphy-navigation', BDM_URI . '/assets/js/navigation.js', array(), BDM_VERSION, true);
wp_enqueue_script('bd-murphy-social-share', BDM_URI . '/assets/js/social-share.js', array(), BDM_VERSION, true);
wp_localize_script('bd-murphy-navigation', 'bdMurphyScreenReaderText', array(
'expand' => __('Expand child menu', 'bd-murphy'),
'collapse' => __('Collapse child menu', 'bd-murphy'),
));
}
add_action('wp_enqueue_scripts', 'bdm_enqueue_assets');
function bdm_enqueue_admin_assets($hook) {
wp_enqueue_style('bd-murphy-admin-style', BDM_URI . '/assets/admin.css', array(), BDM_VERSION);
}
add_action('admin_enqueue_scripts', 'bdm_enqueue_admin_assets');
function bdm_output_customizer_css() {
$primary_color = get_theme_mod('primary_color', '#1B3A6B');
$accent_color = get_theme_mod('accent_color', '#C8A96E');
$cream_color = get_theme_mod('background_color', 'F5F0E8');
$heading_font = get_theme_mod('heading_font', 'Playfair Display');
$body_font = get_theme_mod('body_font', 'Lato');
$slate_blue = bdm_adjust_color($primary_color, 30);
$sky_blue = bdm_adjust_color($primary_color, 80);
echo '<style id="bdm-customizer-styles" type="text/css">' . "\n";
echo ':root {' . "\n";
echo '--bdm-navy: ' . esc_attr($primary_color) . ';' . "\n";
echo '--bdm-slate: ' . esc_attr($slate_blue) . ';' . "\n";
echo '--bdm-sky: ' . esc_attr($sky_blue) . ';' . "\n";
echo '--bdm-gold: ' . esc_attr($accent_color) . ';' . "\n";
echo '--bdm-cream: ' . esc_attr($cream_color) . ';' . "\n";
echo '--bdm-parchment: #EDE4D0;' . "\n";
echo '--bdm-body-text: #2C2C2C;' . "\n";
echo '--bdm-mid-grey: #555555;' . "\n";
echo '--bdm-light-grey: #888888;' . "\n";
echo '--bdm-active-green: #2D6A4F;' . "\n";
echo '--bdm-heading-font: ' . esc_attr($heading_font) . ', Georgia, serif;' . "\n";
echo '--bdm-body-font: ' . esc_attr($body_font) . ', Calibri, sans-serif;' . "\n";
echo '}' . "\n";
echo '</style>' . "\n";
}
add_action('wp_head', 'bdm_output_customizer_css', 99);
function bdm_adjust_color($hex, $percent) {
$hex = ltrim($hex, '#');
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));
$r = min(255, max(0, $r + $percent));
$g = min(255, max(0, $g + $percent));
$b = min(255, max(0, $b + $percent));
return sprintf('#%02x%02x%02x', $r, $g, $b);
}
function bdm_publish_hook($post_id) {
do_action('bdm_post_published', $post_id);
}
add_action('publish_post', 'bdm_publish_hook');
add_action('wp_head', function() {
echo '<link rel="alternate" type="application/rss+xml" title="' . get_bloginfo('name') . ' RSS Feed" href="' . esc_url(get_bloginfo('rss2_url')) . '">' . "\n";
});