144 lines
8.4 KiB
PHP
144 lines
8.4 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;
|
|
}
|
|
|
|
function bdm_theme_options_menu() {
|
|
add_theme_page(
|
|
__('Theme Options', 'bd-murphy'),
|
|
__('Theme Options', 'bd-murphy'),
|
|
'manage_options',
|
|
'bdm-theme-options',
|
|
'bdm_theme_options_page'
|
|
);
|
|
}
|
|
add_action('admin_menu', 'bdm_theme_options_menu');
|
|
|
|
function bdm_register_theme_options() {
|
|
register_setting('bdm_theme_options_group', 'bdm_theme_options', 'bdm_sanitize_theme_options');
|
|
|
|
add_settings_section('bdm_social_section', __('Social Media Links', 'bd-murphy'), 'bdm_social_section_callback', 'bdm-theme-options');
|
|
add_settings_section('bdm_donate_section', __('Donation Links', 'bd-murphy'), 'bdm_donate_section_callback', 'bdm-theme-options');
|
|
add_settings_section('bdm_author_section', __('Author Settings', 'bd-murphy'), 'bdm_author_section_callback', 'bdm-theme-options');
|
|
add_settings_section('bdm_business_section', __('Business Information (CAN-SPAM)', 'bd-murphy'), 'bdm_business_section_callback', 'bdm-theme-options');
|
|
add_settings_section('bdm_navigation_section', __('Navigation Settings', 'bd-murphy'), 'bdm_navigation_section_callback', 'bdm-theme-options');
|
|
|
|
add_settings_field('twitter_url', __('X/Twitter URL', 'bd-murphy'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_social_section', array('key' => 'twitter_url', 'label' => __('X/Twitter profile URL', 'bd-murphy')));
|
|
add_settings_field('facebook_url', __('Facebook URL', 'bd-murphy'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_social_section', array('key' => 'facebook_url', 'label' => __('Facebook page URL', 'bd-murphy')));
|
|
add_settings_field('linkedin_url', __('LinkedIn URL', 'bd-murphy'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_social_section', array('key' => 'linkedin_url', 'label' => __('LinkedIn profile URL', 'bd-murphy')));
|
|
add_settings_field('instagram_url', __('Instagram URL', 'bd-murphy'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_social_section', array('key' => 'instagram_url', 'label' => __('Instagram profile URL', 'bd-murphy')));
|
|
|
|
add_settings_field('buymeacoffee_url', __('Buy Me a Coffee URL', 'bd-murphy'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_donate_section', array('key' => 'buymeacoffee_url', 'label' => __('Buy Me a Coffee page URL', 'bd-murphy')));
|
|
add_settings_field('paypal_url', __('PayPal URL', 'bd-murphy'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_donate_section', array('key' => 'paypal_url', 'label' => __('PayPal.me or donation URL', 'bd-murphy')));
|
|
|
|
add_settings_field('author_photo_id', __('Author Photo', 'bd-murphy'), 'bdm_media_field_callback', 'bdm-theme-options', 'bdm_author_section', array('key' => 'author_photo_id', 'label' => __('Author photo (WordPress media attachment ID)', 'bd-murphy')));
|
|
|
|
add_settings_field('business_name', __('Business Name', 'bd-murphy'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_business_section', array('key' => 'business_name', 'label' => __('Legal business name', 'bd-murphy')));
|
|
add_settings_field('business_address_1', __('Address Line 1', 'bd-murphy'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_business_section', array('key' => 'business_address_1', 'label' => __('Street address', 'bd-murphy')));
|
|
add_settings_field('business_address_2', __('Address Line 2', 'bd-murphy'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_business_section', array('key' => 'business_address_2', 'label' => __('Suite, unit, PO box', 'bd-murphy')));
|
|
add_settings_field('business_city', __('City / State / Postal', 'bd-murphy'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_business_section', array('key' => 'business_city', 'label' => __('City / State / Postal code', 'bd-murphy')));
|
|
add_settings_field('business_country', __('Country', 'bd-murphy'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_business_section', array('key' => 'business_country', 'label' => __('Country', 'bd-murphy')));
|
|
add_settings_field('business_phone', __('Phone Number', 'bd-murphy'), 'bdm_text_field_callback', 'bdm-theme-options', 'bdm_business_section', array('key' => 'business_phone', 'label' => __('Phone number (optional)', 'bd-murphy')));
|
|
|
|
add_settings_field('sticky_nav', __('Sticky Navigation', 'bd-murphy'), 'bdm_checkbox_field_callback', 'bdm-theme-options', 'bdm_navigation_section', array('key' => 'sticky_nav', 'label' => __('Enable sticky navigation', 'bd-murphy'), 'default' => true));
|
|
add_settings_field('posts_per_page', __('Posts Per Page', 'bd-murphy'), 'bdm_number_field_callback', 'bdm-theme-options', 'bdm_navigation_section', array('key' => 'posts_per_page', 'label' => __('Blog posts per page', 'bd-murphy'), 'default' => 10));
|
|
add_settings_field('show_read_time', __('Read Time', 'bd-murphy'), 'bdm_checkbox_field_callback', 'bdm-theme-options', 'bdm_navigation_section', array('key' => 'show_read_time', 'label' => __('Show read time on posts', 'bd-murphy'), 'default' => true));
|
|
}
|
|
add_action('admin_init', 'bdm_register_theme_options');
|
|
|
|
function bdm_get_theme_option($key, $default = '') {
|
|
$options = get_option('bdm_theme_options', array());
|
|
return isset($options[$key]) ? $options[$key] : $default;
|
|
}
|
|
|
|
function bdm_sanitize_theme_options($input) {
|
|
$sanitized = array();
|
|
foreach ($input as $key => $value) {
|
|
if (in_array($key, array('buymeacoffee_url', 'paypal_url', 'twitter_url', 'facebook_url', 'linkedin_url', 'instagram_url'))) {
|
|
$sanitized[$key] = esc_url_raw($value);
|
|
} elseif ($key === 'business_phone') {
|
|
$sanitized[$key] = sanitize_text_field($value);
|
|
} else {
|
|
$sanitized[$key] = sanitize_text_field($value);
|
|
}
|
|
}
|
|
return $sanitized;
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
function bdm_social_section_callback() {
|
|
echo '<p>' . esc_html__('Enter your social media profile URLs.', 'bd-murphy') . '</p>';
|
|
}
|
|
|
|
function bdm_donate_section_callback() {
|
|
echo '<p>' . esc_html__('Enter your donation page URLs.', 'bd-murphy') . '</p>';
|
|
}
|
|
|
|
function bdm_author_section_callback() {
|
|
echo '<p>' . esc_html__('Configure author settings.', 'bd-murphy') . '</p>';
|
|
}
|
|
|
|
function bdm_business_section_callback() {
|
|
echo '<p>' . esc_html__('Business information required for CAN-SPAM compliance.', 'bd-murphy') . '</p>';
|
|
}
|
|
|
|
function bdm_navigation_section_callback() {
|
|
echo '<p>' . esc_html__('Configure navigation and blog settings.', 'bd-murphy') . '</p>';
|
|
}
|
|
|
|
function bdm_text_field_callback($args) {
|
|
$key = $args['key'];
|
|
$value = bdm_get_theme_option($key);
|
|
echo '<input type="text" id="bdm_' . esc_attr($key) . '" name="bdm_theme_options[' . esc_attr($key) . ']" value="' . esc_attr($value) . '" class="regular-text">';
|
|
if (!empty($args['label'])) {
|
|
echo '<p class="description">' . esc_html($args['label']) . '</p>';
|
|
}
|
|
}
|
|
|
|
function bdm_checkbox_field_callback($args) {
|
|
$key = $args['key'];
|
|
$value = bdm_get_theme_option($key, $args['default'] ?? false);
|
|
echo '<input type="checkbox" id="bdm_' . esc_attr($key) . '" name="bdm_theme_options[' . esc_attr($key) . ']" value="1"' . checked($value, true, false) . '>';
|
|
echo '<label for="bdm_' . esc_attr($key) . '">' . esc_html($args['label']) . '</label>';
|
|
}
|
|
|
|
function bdm_number_field_callback($args) {
|
|
$key = $args['key'];
|
|
$value = bdm_get_theme_option($key, $args['default'] ?? 10);
|
|
echo '<input type="number" id="bdm_' . esc_attr($key) . '" name="bdm_theme_options[' . esc_attr($key) . ']" value="' . esc_attr($value) . '" class="small-text">';
|
|
echo '<p class="description">' . esc_html($args['label']) . '</p>';
|
|
}
|
|
|
|
function bdm_media_field_callback($args) {
|
|
$key = $args['key'];
|
|
$value = bdm_get_theme_option($key);
|
|
echo '<input type="text" id="bdm_' . esc_attr($key) . '" name="bdm_theme_options[' . esc_attr($key) . ']" value="' . esc_attr($value) . '" class="small-text">';
|
|
echo '<p class="description">' . esc_html($args['label']) . '</p>';
|
|
}
|