Continues the Bookshelf history. The three plugins tracked there are consolidated into umbra-bookshelf/ and this repository becomes the canonical home for the plugin and the theme. bd-bookshelf/ -> theme/ separate artifact, name unchanged (root specs) -> umbra-bookshelf/spec/ aligned to Umbra Bookshelf old plugin zips -> archive/pre-umbra-releases/ Adds a repository README and drops the Bookshelf closure notice.
204 lines
9.8 KiB
PHP
204 lines
9.8 KiB
PHP
<?php
|
|
// Copyright 2026 Umbra Tools (umbratools.com)
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
/**
|
|
* Theme Options Admin Page
|
|
*
|
|
* @package BD_Murphy
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Add Theme Options menu page
|
|
*/
|
|
function bdm_theme_options_menu() {
|
|
add_theme_page(
|
|
esc_html__('Theme Options', 'bd-bookshelf'),
|
|
esc_html__('Theme Options', 'bd-bookshelf'),
|
|
'manage_options',
|
|
'bdm-theme-options',
|
|
'bdm_theme_options_page'
|
|
);
|
|
}
|
|
add_action('admin_menu', 'bdm_theme_options_menu');
|
|
|
|
/**
|
|
* Register theme options
|
|
*/
|
|
function bdm_register_theme_options() {
|
|
register_setting('bdm_theme_options_group', 'bdm_theme_options', 'bdm_sanitize_theme_options');
|
|
|
|
// Social Media Section
|
|
add_settings_section('bdm_social_section', esc_html__('Social Media Links', 'bd-bookshelf'), 'bdm_social_section_callback', 'bdm-theme-options');
|
|
|
|
add_settings_field('twitter_url', esc_html__('X/Twitter URL', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_social_section', array('key' => 'twitter_url', 'label' => esc_html__('X/Twitter profile URL', 'bd-bookshelf')));
|
|
add_settings_field('facebook_url', esc_html__('Facebook URL', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_social_section', array('key' => 'facebook_url', 'label' => esc_html__('Facebook page URL', 'bd-bookshelf')));
|
|
add_settings_field('linkedin_url', esc_html__('LinkedIn URL', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_social_section', array('key' => 'linkedin_url', 'label' => esc_html__('LinkedIn profile URL', 'bd-bookshelf')));
|
|
add_settings_field('instagram_url', esc_html__('Instagram URL', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_social_section', array('key' => 'instagram_url', 'label' => esc_html__('Instagram profile URL', 'bd-bookshelf')));
|
|
|
|
// Donation Section
|
|
add_settings_section('bdm_donate_section', esc_html__('Donation Links', 'bd-bookshelf'), 'bdm_donate_section_callback', 'bdm-theme-options');
|
|
|
|
add_settings_field('venmo_url', esc_html__('Venmo URL', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_donate_section', array('key' => 'venmo_url', 'label' => esc_html__('Venmo profile URL', 'bd-bookshelf')));
|
|
add_settings_field('paypal_url', esc_html__('PayPal URL', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_donate_section', array('key' => 'paypal_url', 'label' => esc_html__('PayPal.me or donation URL', 'bd-bookshelf')));
|
|
add_settings_field('buymeacoffee_url', esc_html__('Buy Me a Coffee URL', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_donate_section', array('key' => 'buymeacoffee_url', 'label' => esc_html__('Buy Me a Coffee page URL', 'bd-bookshelf'), 'default' => 'https://buymeacoffee.com/bdmurph73I'));
|
|
|
|
// Author Section
|
|
add_settings_section('bdm_author_section', esc_html__('Author Settings', 'bd-bookshelf'), 'bdm_author_section_callback', 'bdm-theme-options');
|
|
|
|
add_settings_field('author_photo_id', esc_html__('Author Photo', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_author_section', array('key' => 'author_photo_id', 'label' => esc_html__('Author photo (WordPress media attachment ID)', 'bd-bookshelf')));
|
|
|
|
// Business Section (CAN-SPAM)
|
|
add_settings_section('bdm_business_section', esc_html__('Business Information (CAN-SPAM)', 'bd-bookshelf'), 'bdm_business_section_callback', 'bdm-theme-options');
|
|
|
|
add_settings_field('business_name', esc_html__('Business Name', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_business_section', array('key' => 'business_name', 'label' => esc_html__('Legal business name', 'bd-bookshelf')));
|
|
add_settings_field('business_address_1', esc_html__('Address Line 1', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_business_section', array('key' => 'business_address_1', 'label' => esc_html__('Street address', 'bd-bookshelf')));
|
|
add_settings_field('business_address_2', esc_html__('Address Line 2', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_business_section', array('key' => 'business_address_2', 'label' => esc_html__('Suite, unit, PO box', 'bd-bookshelf')));
|
|
add_settings_field('business_city', esc_html__('City / State / Postal', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_business_section', array('key' => 'business_city', 'label' => esc_html__('City / State / Postal code', 'bd-bookshelf')));
|
|
add_settings_field('business_country', esc_html__('Country', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_business_section', array('key' => 'business_country', 'label' => esc_html__('Country', 'bd-bookshelf')));
|
|
add_settings_field('business_phone', esc_html__('Phone Number', 'bd-bookshelf'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_business_section', array('key' => 'business_phone', 'label' => esc_html__('Phone number (optional)', 'bd-bookshelf')));
|
|
|
|
// Navigation Section
|
|
add_settings_section('bdm_navigation_section', esc_html__('Navigation Settings', 'bd-bookshelf'), 'bdm_navigation_section_callback', 'bdm-theme-options');
|
|
|
|
add_settings_field('sticky_nav', esc_html__('Sticky Navigation', 'bd-bookshelf'), 'bdm_checkbox_field_callback', 'bdm-theme-options', 'bdm_navigation_section', array('key' => 'sticky_nav', 'label' => esc_html__('Enable sticky navigation', 'bd-bookshelf'), 'default' => true));
|
|
add_settings_field('posts_per_page', esc_html__('Posts Per Page', 'bd-bookshelf'), 'bdm_number_field_callback', 'bdm-theme-options', 'bdm_navigation_section', array('key' => 'posts_per_page', 'label' => esc_html__('Blog posts per page', 'bd-bookshelf'), 'default' => 10));
|
|
add_settings_field('show_read_time', esc_html__('Read Time', 'bd-bookshelf'), 'bdm_checkbox_field_callback', 'bdm-theme-options', 'bdm_navigation_section', array('key' => 'show_read_time', 'label' => esc_html__('Show read time on posts', 'bd-bookshelf'), 'default' => true));
|
|
}
|
|
add_action('admin_init', 'bdm_register_theme_options');
|
|
|
|
/**
|
|
* Get theme option value
|
|
*
|
|
* @param string $key Option key.
|
|
* @param mixed $default Default value.
|
|
* @return mixed
|
|
*/
|
|
function bdm_get_theme_option($key, $default = '') {
|
|
$options = get_option('bdm_theme_options', array());
|
|
return isset($options[$key]) ? $options[$key] : $default;
|
|
}
|
|
|
|
/**
|
|
* Sanitize theme options
|
|
*
|
|
* @param array $input Input values.
|
|
* @return array
|
|
*/
|
|
function bdm_sanitize_theme_options($input) {
|
|
$sanitized = array();
|
|
|
|
$url_fields = array('buymeacoffee_url', 'paypal_url', 'twitter_url', 'facebook_url', 'linkedin_url', 'instagram_url');
|
|
|
|
foreach ($input as $key => $value) {
|
|
if (in_array($key, $url_fields, true)) {
|
|
$sanitized[$key] = esc_url_raw($value);
|
|
} elseif ('business_phone' === $key) {
|
|
$sanitized[$key] = preg_replace('/[^0-9+\-\s\(\)]/', '', $value);
|
|
} else {
|
|
$sanitized[$key] = sanitize_text_field($value);
|
|
}
|
|
}
|
|
|
|
return $sanitized;
|
|
}
|
|
|
|
/**
|
|
* Render Theme Options page
|
|
*/
|
|
function bdm_theme_options_page() {
|
|
if (!current_user_can('manage_options')) {
|
|
return;
|
|
}
|
|
?>
|
|
<div class="wrap">
|
|
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
|
|
<form method="post" action="options.php">
|
|
<?php
|
|
settings_fields('bdm_theme_options_group');
|
|
do_settings_sections('bdm-theme-options');
|
|
submit_button();
|
|
?>
|
|
</form>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
// Section Callbacks
|
|
function bdm_social_section_callback() {
|
|
echo '<p>' . esc_html__('Enter your social media profile URLs.', 'bd-bookshelf') . '</p>';
|
|
}
|
|
|
|
function bdm_donate_section_callback() {
|
|
echo '<p>' . esc_html__('Enter your donation page URLs.', 'bd-bookshelf') . '</p>';
|
|
}
|
|
|
|
function bdm_author_section_callback() {
|
|
echo '<p>' . esc_html__('Configure author settings.', 'bd-bookshelf') . '</p>';
|
|
}
|
|
|
|
function bdm_business_section_callback() {
|
|
echo '<p>' . esc_html__('Business information required for CAN-SPAM compliance.', 'bd-bookshelf') . '</p>';
|
|
}
|
|
|
|
function bdm_navigation_section_callback() {
|
|
echo '<p>' . esc_html__('Configure navigation and blog settings.', 'bd-bookshelf') . '</p>';
|
|
}
|
|
|
|
// Field Callbacks
|
|
function bdm_text_field_callback($args) {
|
|
$key = $args['key'];
|
|
$value = bdm_get_theme_option($key);
|
|
printf(
|
|
'<input type="text" id="bdm_%s" name="bdm_theme_options[%s]" value="%s" class="regular-text">',
|
|
esc_attr($key),
|
|
esc_attr($key),
|
|
esc_attr($value)
|
|
);
|
|
if (!empty($args['label'])) {
|
|
printf('<p class="description">%s</p>', esc_html($args['label']));
|
|
}
|
|
}
|
|
|
|
function bdm_checkbox_field_callback($args) {
|
|
$key = $args['key'];
|
|
$value = bdm_get_theme_option($key, $args['default'] ?? false);
|
|
$checked = checked($value, true, false);
|
|
|
|
printf(
|
|
'<input type="checkbox" id="bdm_%s" name="bdm_theme_options[%s]" value="1"%s>',
|
|
esc_attr($key),
|
|
esc_attr($key),
|
|
$checked
|
|
);
|
|
printf(' <label for="bdm_%s">%s</label>', esc_attr($key), esc_html($args['label']));
|
|
}
|
|
|
|
function bdm_number_field_callback($args) {
|
|
$key = $args['key'];
|
|
$value = bdm_get_theme_option($key, $args['default'] ?? 10);
|
|
printf(
|
|
'<input type="number" id="bdm_%s" name="bdm_theme_options[%s]" value="%s" class="small-text">',
|
|
esc_attr($key),
|
|
esc_attr($key),
|
|
esc_attr($value)
|
|
);
|
|
printf('<p class="description">%s</p>', esc_html($args['label']));
|
|
}
|
|
|
|
function bdm_media_field_callback($args) {
|
|
$key = $args['key'];
|
|
$value = bdm_get_theme_option($key);
|
|
printf(
|
|
'<input type="text" id="bdm_%s" name="bdm_theme_options[%s]" value="%s" class="small-text">',
|
|
esc_attr($key),
|
|
esc_attr($key),
|
|
esc_attr($value)
|
|
);
|
|
printf('<p class="description">%s</p>', esc_html($args['label']));
|
|
}
|