I’ll build this as a strong inc/admin/admin-page.php file for your Rx theme: menu pages, settings registration, sanitization, admin assets, status tools, import/export, reset options, and useful tabs.
Below is a large advanced inc/admin/admin-page.php file for your Rx Theme. It adds many admin functionalities: theme dashboard, settings tabs, performance options, header/footer scripts, SEO, social, layout, typography, security, backup/import/export, reset, system status, and safe sanitization.
Create this file:
<?php
/**
* Rx Theme Admin Page
*
* File: inc/admin/admin-page.php
*
* Advanced admin panel for Rx Theme.
*
* @package RxTheme
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Safety constants fallback.
*/
if ( ! defined( 'RX_THEME_VERSION' ) ) {
define( 'RX_THEME_VERSION', wp_get_theme()->get( 'Version' ) ? wp_get_theme()->get( 'Version' ) : '1.0.0' );
}
if ( ! defined( 'RX_THEME_NAME' ) ) {
define( 'RX_THEME_NAME', wp_get_theme()->get( 'Name' ) ? wp_get_theme()->get( 'Name' ) : 'Rx Theme' );
}
/**
* Main admin class.
*/
if ( ! class_exists( 'Rx_Theme_Admin_Page' ) ) :
final class Rx_Theme_Admin_Page {
/**
* Option key.
*
* @var string
*/
const OPTION_KEY = 'rx_theme_options';
/**
* Nonce action.
*
* @var string
*/
const NONCE_ACTION = 'rx_theme_admin_action';
/**
* Nonce name.
*
* @var string
*/
const NONCE_NAME = 'rx_theme_admin_nonce';
/**
* Admin page slug.
*
* @var string
*/
const PAGE_SLUG = 'rx-theme';
/**
* Constructor.
*/
public function __construct() {
add_action( 'admin_menu', array( $this, 'register_admin_menu' ) );
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'admin_init', array( $this, 'handle_admin_actions' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
add_filter( 'plugin_action_links', array( $this, 'theme_admin_quick_links' ), 10, 2 );
}
/**
* Default theme options.
*
* @return array
*/
public static function defaults() {
return array(
'general' => array(
'enable_theme_panel' => 1,
'enable_back_to_top' => 1,
'enable_breadcrumbs' => 1,
'enable_reading_time' => 1,
'enable_post_views' => 0,
'enable_ajax_search' => 0,
'enable_smooth_scroll' => 1,
'enable_lazyload' => 1,
'enable_dark_mode_toggle' => 0,
'admin_footer_text' => 'Thank you for using Rx Theme.',
),
'layout' => array(
'site_width' => '1200',
'content_width' => '760',
'sidebar_width' => '320',
'global_layout' => 'right-sidebar',
'archive_layout' => 'grid',
'single_layout' => 'right-sidebar',
'page_layout' => 'no-sidebar',
'sticky_header' => 1,
'transparent_header' => 0,
'boxed_layout' => 0,
),
'colors' => array(
'primary_color' => '#0b63ce',
'secondary_color' => '#00a884',
'accent_color' => '#ff6b00',
'body_bg_color' => '#ffffff',
'body_text_color' => '#222222',
'heading_color' => '#111111',
'link_color' => '#0b63ce',
'link_hover_color' => '#084b9c',
'header_bg_color' => '#ffffff',
'footer_bg_color' => '#111827',
'footer_text_color' => '#ffffff',
),
'typography' => array(
'body_font_family' => 'system',
'heading_font_family' => 'system',
'body_font_size' => '16',
'body_line_height' => '1.7',
'heading_line_height' => '1.25',
'paragraph_margin_bottom' => '18',
'enable_font_preload' => 0,
'font_preload_url_1' => '',
'font_preload_url_2' => '',
'font_preload_url_3' => '',
),
'seo' => array(
'enable_schema' => 1,
'enable_article_schema' => 1,
'enable_breadcrumb_schema' => 1,
'enable_open_graph' => 1,
'enable_twitter_cards' => 1,
'enable_meta_description' => 0,
'enable_canonical_url' => 1,
'enable_author_meta' => 1,
'enable_updated_date' => 1,
'default_og_image' => '',
'twitter_username' => '',
),
'performance' => array(
'disable_emojis' => 1,
'disable_embeds' => 0,
'disable_dashicons_front' => 1,
'remove_wp_version' => 1,
'remove_shortlink' => 1,
'remove_rsd_link' => 1,
'remove_wlwmanifest' => 1,
'defer_js' => 0,
'async_js' => 0,
'preload_main_css' => 0,
'preconnect_google_fonts' => 0,
'dns_prefetch_urls' => '',
'preconnect_urls' => '',
'preload_urls' => '',
'enable_local_cache_hint' => 0,
),
'security' => array(
'disable_xmlrpc' => 0,
'disable_rest_user_enum' => 1,
'remove_login_errors' => 1,
'disable_file_edit' => 0,
'disable_author_archives' => 0,
'add_security_headers' => 0,
'disable_feed' => 0,
),
'blog' => array(
'enable_related_posts' => 1,
'related_posts_count' => 4,
'related_posts_by' => 'category',
'enable_author_box' => 1,
'enable_social_share' => 1,
'enable_post_navigation' => 1,
'enable_table_of_contents' => 0,
'excerpt_length' => 28,
'archive_posts_per_row' => 3,
'show_featured_image' => 1,
'show_category' => 1,
'show_tags' => 1,
'show_date' => 1,
'show_author' => 1,
'show_comments_count' => 1,
),
'social' => array(
'facebook_url' => '',
'twitter_url' => '',
'linkedin_url' => '',
'youtube_url' => '',
'instagram_url' => '',
'pinterest_url' => '',
'tiktok_url' => '',
'github_url' => '',
'whatsapp_number' => '',
'telegram_url' => '',
),
'header_footer' => array(
'header_html' => '',
'footer_html' => '',
'before_body_close_html' => '',
'custom_css' => '',
'custom_js' => '',
'analytics_code' => '',
'adsense_code' => '',
'verification_meta' => '',
),
'advanced' => array(
'enable_debug_info' => 0,
'enable_safe_mode' => 0,
'enable_custom_body_class' => 0,
'custom_body_classes' => '',
'custom_post_types_support'=> 0,
'maintenance_mode' => 0,
'maintenance_message' => 'Website is under maintenance. Please come back soon.',
),
);
}
/**
* Get all options merged with defaults.
*
* @return array
*/
public static function get_options() {
$saved = get_option( self::OPTION_KEY, array() );
$defaults = self::defaults();
if ( ! is_array( $saved ) ) {
$saved = array();
}
return self::array_merge_recursive_distinct( $defaults, $saved );
}
/**
* Get a single option.
*
* @param string $section Section.
* @param string $key Key.
* @param mixed $default Default.
*
* @return mixed
*/
public static function get_option( $section, $key, $default = null ) {
$options = self::get_options();
if ( isset( $options[ $section ][ $key ] ) ) {
return $options[ $section ][ $key ];
}
return $default;
}
/**
* Recursive merge.
*
* @param array $array1 First.
* @param array $array2 Second.
*
* @return array
*/
private static function array_merge_recursive_distinct( array $array1, array $array2 ) {
$merged = $array1;
foreach ( $array2 as $key => $value ) {
if (
is_array( $value )
&& isset( $merged[ $key ] )
&& is_array( $merged[ $key ] )
) {
$merged[ $key ] = self::array_merge_recursive_distinct( $merged[ $key ], $value );
} else {
$merged[ $key ] = $value;
}
}
return $merged;
}
/**
* Register admin menu.
*/
public function register_admin_menu() {
add_theme_page(
__( 'Rx Theme Panel', 'rx-theme' ),
__( 'Rx Theme', 'rx-theme' ),
'manage_options',
self::PAGE_SLUG,
array( $this, 'render_admin_page' )
);
}
/**
* Register settings.
*/
public function register_settings() {
register_setting(
'rx_theme_options_group',
self::OPTION_KEY,
array(
'type' => 'array',
'sanitize_callback' => array( $this, 'sanitize_options' ),
'default' => self::defaults(),
)
);
}
/**
* Sanitize options.
*
* @param array $input Input.
*
* @return array
*/
public function sanitize_options( $input ) {
$defaults = self::defaults();
$output = self::get_options();
if ( ! is_array( $input ) ) {
return $output;
}
foreach ( $defaults as $section => $fields ) {
if ( ! isset( $input[ $section ] ) || ! is_array( $input[ $section ] ) ) {
continue;
}
foreach ( $fields as $key => $default_value ) {
$value = isset( $input[ $section ][ $key ] ) ? $input[ $section ][ $key ] : $default_value;
if ( is_int( $default_value ) ) {
$output[ $section ][ $key ] = absint( $value );
} elseif ( $this->is_color_field( $key ) ) {
$output[ $section ][ $key ] = sanitize_hex_color( $value ) ? sanitize_hex_color( $value ) : $default_value;
} elseif ( $this->is_url_field( $key ) ) {
$output[ $section ][ $key ] = esc_url_raw( $value );
} elseif ( $this->is_code_field( $key ) ) {
$output[ $section ][ $key ] = wp_kses_post( $value );
} elseif ( $this->is_css_field( $key ) ) {
$output[ $section ][ $key ] = wp_strip_all_tags( $value );
} elseif ( $this->is_js_field( $key ) ) {
$output[ $section ][ $key ] = wp_kses_post( $value );
} elseif ( $this->is_textarea_field( $key ) ) {
$output[ $section ][ $key ] = sanitize_textarea_field( $value );
} elseif ( is_numeric( $default_value ) ) {
$output[ $section ][ $key ] = sanitize_text_field( $value );
} else {
$output[ $section ][ $key ] = sanitize_text_field( $value );
}
}
}
add_settings_error(
self::OPTION_KEY,
'rx_theme_options_saved',
__( 'Rx Theme settings saved successfully.', 'rx-theme' ),
'updated'
);
return $output;
}
/**
* Check color field.
*/
private function is_color_field( $key ) {
return false !== strpos( $key, 'color' );
}
/**
* Check URL field.
*/
private function is_url_field( $key ) {
return false !== strpos( $key, 'url' ) || false !== strpos( $key, 'image' );
}
/**
* Check code field.
*/
private function is_code_field( $key ) {
$fields = array(
'header_html',
'footer_html',
'before_body_close_html',
'analytics_code',
'adsense_code',
'verification_meta',
);
return in_array( $key, $fields, true );
}
/**
* Check CSS field.
*/
private function is_css_field( $key ) {
return 'custom_css' === $key;
}
/**
* Check JS field.
*/
private function is_js_field( $key ) {
return 'custom_js' === $key;
}
/**
* Check textarea field.
*/
private function is_textarea_field( $key ) {
$fields = array(
'dns_prefetch_urls',
'preconnect_urls',
'preload_urls',
'admin_footer_text',
'maintenance_message',
'custom_body_classes',
);
return in_array( $key, $fields, true );
}
/**
* Handle admin actions: reset/export/import.
*/
public function handle_admin_actions() {
if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
return;
}
if ( empty( $_GET['page'] ) || self::PAGE_SLUG !== sanitize_key( wp_unslash( $_GET['page'] ) ) ) {
return;
}
if ( isset( $_POST['rx_theme_reset_options'] ) ) {
$this->verify_nonce();
update_option( self::OPTION_KEY, self::defaults() );
wp_safe_redirect(
add_query_arg(
array(
'page' => self::PAGE_SLUG,
'message' => 'reset',
),
admin_url( 'themes.php' )
)
);
exit;
}
if ( isset( $_POST['rx_theme_export_options'] ) ) {
$this->verify_nonce();
$this->export_options();
}
if ( isset( $_POST['rx_theme_import_options'] ) ) {
$this->verify_nonce();
$this->import_options();
}
}
/**
* Verify nonce.
*/
private function verify_nonce() {
if (
! isset( $_POST[ self::NONCE_NAME ] )
|| ! wp_verify_nonce(
sanitize_text_field( wp_unslash( $_POST[ self::NONCE_NAME ] ) ),
self::NONCE_ACTION
)
) {
wp_die( esc_html__( 'Security check failed.', 'rx-theme' ) );
}
}
/**
* Export options as JSON.
*/
private function export_options() {
$options = self::get_options();
nocache_headers();
header( 'Content-Type: application/json; charset=utf-8' );
header( 'Content-Disposition: attachment; filename=rx-theme-options-' . gmdate( 'Y-m-d-H-i-s' ) . '.json' );
echo wp_json_encode(
array(
'theme' => RX_THEME_NAME,
'version' => RX_THEME_VERSION,
'exported' => gmdate( 'c' ),
'options' => $options,
),
JSON_PRETTY_PRINT
);
exit;
}
/**
* Import options from JSON.
*/
private function import_options() {
if ( empty( $_FILES['rx_theme_import_file']['tmp_name'] ) ) {
wp_safe_redirect(
add_query_arg(
array(
'page' => self::PAGE_SLUG,
'message' => 'import_empty',
),
admin_url( 'themes.php' )
)
);
exit;
}
$file = $_FILES['rx_theme_import_file'];
if ( ! empty( $file['error'] ) ) {
wp_safe_redirect(
add_query_arg(
array(
'page' => self::PAGE_SLUG,
'message' => 'import_error',
),
admin_url( 'themes.php' )
)
);
exit;
}
$raw = file_get_contents( $file['tmp_name'] );
if ( empty( $raw ) ) {
wp_safe_redirect(
add_query_arg(
array(
'page' => self::PAGE_SLUG,
'message' => 'import_empty',
),
admin_url( 'themes.php' )
)
);
exit;
}
$data = json_decode( $raw, true );
if ( ! is_array( $data ) || empty( $data['options'] ) || ! is_array( $data['options'] ) ) {
wp_safe_redirect(
add_query_arg(
array(
'page' => self::PAGE_SLUG,
'message' => 'import_invalid',
),
admin_url( 'themes.php' )
)
);
exit;
}
$sanitized = $this->sanitize_options( $data['options'] );
update_option( self::OPTION_KEY, $sanitized );
wp_safe_redirect(
add_query_arg(
array(
'page' => self::PAGE_SLUG,
'message' => 'import_success',
),
admin_url( 'themes.php' )
)
);
exit;
}
/**
* Admin notices.
*/
public function admin_notices() {
if ( empty( $_GET['page'] ) || self::PAGE_SLUG !== sanitize_key( wp_unslash( $_GET['page'] ) ) ) {
return;
}
if ( empty( $_GET['message'] ) ) {
return;
}
$message = sanitize_key( wp_unslash( $_GET['message'] ) );
$messages = array(
'reset' => __( 'Rx Theme options reset successfully.', 'rx-theme' ),
'import_success' => __( 'Rx Theme options imported successfully.', 'rx-theme' ),
'import_empty' => __( 'Import file is empty or missing.', 'rx-theme' ),
'import_error' => __( 'Import failed because the file could not be uploaded.', 'rx-theme' ),
'import_invalid' => __( 'Import failed because the JSON file is invalid.', 'rx-theme' ),
);
if ( isset( $messages[ $message ] ) ) {
$type = in_array( $message, array( 'import_empty', 'import_error', 'import_invalid' ), true ) ? 'error' : 'success';
printf(
'<div class="notice notice-%1$s is-dismissible"><p>%2$s</p></div>',
esc_attr( $type ),
esc_html( $messages[ $message ] )
);
}
}
/**
* Enqueue admin CSS and JS.
*
* @param string $hook Hook.
*/
public function enqueue_admin_assets( $hook ) {
if ( 'appearance_page_' . self::PAGE_SLUG !== $hook ) {
return;
}
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
wp_register_style( 'rx-theme-admin-inline', false, array(), RX_THEME_VERSION );
wp_enqueue_style( 'rx-theme-admin-inline' );
wp_add_inline_style( 'rx-theme-admin-inline', $this->admin_css() );
wp_register_script( 'rx-theme-admin-inline', false, array( 'jquery', 'wp-color-picker' ), RX_THEME_VERSION, true );
wp_enqueue_script( 'rx-theme-admin-inline' );
wp_add_inline_script( 'rx-theme-admin-inline', $this->admin_js() );
}
/**
* Admin CSS.
*
* @return string
*/
private function admin_css() {
return '
.rx-admin-wrap {
max-width: 1280px;
}
.rx-admin-header {
background: linear-gradient(135deg, #0b63ce, #00a884);
color: #fff;
padding: 28px;
border-radius: 14px;
margin: 20px 0;
box-shadow: 0 10px 30px rgba(0,0,0,.10);
}
.rx-admin-header h1 {
color: #fff;
margin: 0 0 8px;
font-size: 32px;
line-height: 1.2;
}
.rx-admin-header p {
margin: 0;
font-size: 15px;
opacity: .95;
}
.rx-admin-grid {
display: grid;
grid-template-columns: 260px 1fr;
gap: 22px;
align-items: start;
}
.rx-admin-tabs {
background: #fff;
border: 1px solid #dcdcde;
border-radius: 12px;
overflow: hidden;
position: sticky;
top: 40px;
}
.rx-admin-tabs a {
display: block;
padding: 13px 16px;
text-decoration: none;
border-bottom: 1px solid #f0f0f1;
color: #1d2327;
font-weight: 600;
}
.rx-admin-tabs a.active,
.rx-admin-tabs a:hover {
background: #f0f6ff;
color: #0b63ce;
}
.rx-admin-panel {
background: #fff;
border: 1px solid #dcdcde;
border-radius: 12px;
padding: 22px;
margin-bottom: 22px;
}
.rx-admin-panel h2 {
margin-top: 0;
font-size: 22px;
}
.rx-field {
display: grid;
grid-template-columns: 260px 1fr;
gap: 18px;
padding: 18px 0;
border-bottom: 1px solid #f0f0f1;
}
.rx-field:last-child {
border-bottom: 0;
}
.rx-field label {
font-weight: 700;
color: #1d2327;
}
.rx-field-description {
color: #646970;
margin-top: 6px;
font-size: 13px;
}
.rx-input,
.rx-select,
.rx-textarea {
width: 100%;
max-width: 720px;
}
.rx-textarea {
min-height: 110px;
font-family: Consolas, Monaco, monospace;
}
.rx-code-textarea {
min-height: 180px;
font-family: Consolas, Monaco, monospace;
font-size: 13px;
}
.rx-checkbox-label {
display: inline-flex;
align-items: center;
gap: 8px;
font-weight: 600;
}
.rx-card-grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 14px;
margin: 18px 0;
}
.rx-stat-card {
background: #f6f7f7;
border: 1px solid #dcdcde;
border-radius: 12px;
padding: 16px;
}
.rx-stat-card strong {
display: block;
font-size: 22px;
color: #0b63ce;
}
.rx-submit-bar {
position: sticky;
bottom: 0;
background: #fff;
border-top: 1px solid #dcdcde;
padding: 15px 0;
z-index: 10;
}
.rx-danger-zone {
border-color: #d63638;
background: #fff8f8;
}
.rx-tools-row {
display: flex;
flex-wrap: wrap;
gap: 12px;
align-items: center;
}
.rx-system-table td,
.rx-system-table th {
padding: 10px 12px;
}
@media (max-width: 960px) {
.rx-admin-grid,
.rx-field,
.rx-card-grid {
grid-template-columns: 1fr;
}
.rx-admin-tabs {
position: static;
}
}
';
}
/**
* Admin JS.
*
* @return string
*/
private function admin_js() {
return "
jQuery(function($){
$('.rx-color-picker').wpColorPicker();
$('.rx-admin-tabs a').on('click', function(e){
e.preventDefault();
var target = $(this).attr('href');
$('.rx-admin-tabs a').removeClass('active');
$(this).addClass('active');
$('.rx-admin-panel[data-panel]').hide();
$(target).show();
if (window.history && window.history.replaceState) {
window.history.replaceState(null, null, target);
}
});
var hash = window.location.hash;
if (hash && $('.rx-admin-tabs a[href=\"' + hash + '\"]').length) {
$('.rx-admin-tabs a[href=\"' + hash + '\"]').trigger('click');
} else {
$('.rx-admin-tabs a:first').trigger('click');
}
$('.rx-confirm-reset').on('click', function(){
return confirm('Are you sure? This will reset all Rx Theme settings.');
});
});
";
}
/**
* Render admin page.
*/
public function render_admin_page() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$options = self::get_options();
?>
<div class="wrap rx-admin-wrap">
<div class="rx-admin-header">
<h1><?php echo esc_html( RX_THEME_NAME ); ?> <?php esc_html_e( 'Control Panel', 'rx-theme' ); ?></h1>
<p>
<?php esc_html_e( 'Advanced settings for design, SEO, performance, security, blog, scripts, and theme tools.', 'rx-theme' ); ?>
<?php echo esc_html__( 'Version:', 'rx-theme' ) . ' ' . esc_html( RX_THEME_VERSION ); ?>
</p>
</div>
<?php settings_errors( self::OPTION_KEY ); ?>
<div class="rx-card-grid">
<div class="rx-stat-card">
<strong><?php echo esc_html( RX_THEME_VERSION ); ?></strong>
<span><?php esc_html_e( 'Theme Version', 'rx-theme' ); ?></span>
</div>
<div class="rx-stat-card">
<strong><?php echo esc_html( get_bloginfo( 'version' ) ); ?></strong>
<span><?php esc_html_e( 'WordPress Version', 'rx-theme' ); ?></span>
</div>
<div class="rx-stat-card">
<strong><?php echo esc_html( PHP_VERSION ); ?></strong>
<span><?php esc_html_e( 'PHP Version', 'rx-theme' ); ?></span>
</div>
<div class="rx-stat-card">
<strong><?php echo esc_html( wp_get_environment_type() ); ?></strong>
<span><?php esc_html_e( 'Environment', 'rx-theme' ); ?></span>
</div>
</div>
<form method="post" action="options.php">
<?php settings_fields( 'rx_theme_options_group' ); ?>
<div class="rx-admin-grid">
<nav class="rx-admin-tabs">
<a href="#rx-general"><?php esc_html_e( 'General', 'rx-theme' ); ?></a>
<a href="#rx-layout"><?php esc_html_e( 'Layout', 'rx-theme' ); ?></a>
<a href="#rx-colors"><?php esc_html_e( 'Colors', 'rx-theme' ); ?></a>
<a href="#rx-typography"><?php esc_html_e( 'Typography', 'rx-theme' ); ?></a>
<a href="#rx-seo"><?php esc_html_e( 'SEO & Schema', 'rx-theme' ); ?></a>
<a href="#rx-performance"><?php esc_html_e( 'Performance', 'rx-theme' ); ?></a>
<a href="#rx-security"><?php esc_html_e( 'Security', 'rx-theme' ); ?></a>
<a href="#rx-blog"><?php esc_html_e( 'Blog', 'rx-theme' ); ?></a>
<a href="#rx-social"><?php esc_html_e( 'Social', 'rx-theme' ); ?></a>
<a href="#rx-header-footer"><?php esc_html_e( 'Header/Footer Code', 'rx-theme' ); ?></a>
<a href="#rx-advanced"><?php esc_html_e( 'Advanced', 'rx-theme' ); ?></a>
<a href="#rx-tools"><?php esc_html_e( 'Tools', 'rx-theme' ); ?></a>
<a href="#rx-status"><?php esc_html_e( 'System Status', 'rx-theme' ); ?></a>
</nav>
<div>
<?php
$this->panel_general( $options );
$this->panel_layout( $options );
$this->panel_colors( $options );
$this->panel_typography( $options );
$this->panel_seo( $options );
$this->panel_performance( $options );
$this->panel_security( $options );
$this->panel_blog( $options );
$this->panel_social( $options );
$this->panel_header_footer( $options );
$this->panel_advanced( $options );
?>
<div class="rx-submit-bar">
<?php submit_button( __( 'Save Rx Theme Settings', 'rx-theme' ), 'primary large', 'submit', false ); ?>
</div>
</div>
</div>
</form>
<?php $this->panel_tools(); ?>
<?php $this->panel_status(); ?>
</div>
<?php
}
/**
* Field name helper.
*/
private function field_name( $section, $key ) {
return self::OPTION_KEY . '[' . esc_attr( $section ) . '][' . esc_attr( $key ) . ']';
}
/**
* Get field value.
*/
private function field_value( $options, $section, $key ) {
return isset( $options[ $section ][ $key ] ) ? $options[ $section ][ $key ] : '';
}
/**
* Render text field.
*/
private function render_text( $options, $section, $key, $label, $description = '', $type = 'text' ) {
$value = $this->field_value( $options, $section, $key );
?>
<div class="rx-field">
<label for="<?php echo esc_attr( $section . '_' . $key ); ?>"><?php echo esc_html( $label ); ?></label>
<div>
<input
class="regular-text rx-input"
type="<?php echo esc_attr( $type ); ?>"
id="<?php echo esc_attr( $section . '_' . $key ); ?>"
name="<?php echo esc_attr( $this->field_name( $section, $key ) ); ?>"
value="<?php echo esc_attr( $value ); ?>"
/>
<?php if ( $description ) : ?>
<p class="rx-field-description"><?php echo esc_html( $description ); ?></p>
<?php endif; ?>
</div>
</div>
<?php
}
/**
* Render textarea field.
*/
private function render_textarea( $options, $section, $key, $label, $description = '', $code = false ) {
$value = $this->field_value( $options, $section, $key );
?>
<div class="rx-field">
<label for="<?php echo esc_attr( $section . '_' . $key ); ?>"><?php echo esc_html( $label ); ?></label>
<div>
<textarea
class="large-text rx-textarea <?php echo $code ? 'rx-code-textarea' : ''; ?>"
id="<?php echo esc_attr( $section . '_' . $key ); ?>"
name="<?php echo esc_attr( $this->field_name( $section, $key ) ); ?>"
><?php echo esc_textarea( $value ); ?></textarea>
<?php if ( $description ) : ?>
<p class="rx-field-description"><?php echo esc_html( $description ); ?></p>
<?php endif; ?>
</div>
</div>
<?php
}
/**
* Render checkbox field.
*/
private function render_checkbox( $options, $section, $key, $label, $description = '' ) {
$value = absint( $this->field_value( $options, $section, $key ) );
?>
<div class="rx-field">
<label><?php echo esc_html( $label ); ?></label>
<div>
<label class="rx-checkbox-label">
<input
type="checkbox"
name="<?php echo esc_attr( $this->field_name( $section, $key ) ); ?>"
value="1"
<?php checked( 1, $value ); ?>
/>
<?php esc_html_e( 'Enable', 'rx-theme' ); ?>
</label>
<?php if ( $description ) : ?>
<p class="rx-field-description"><?php echo esc_html( $description ); ?></p>
<?php endif; ?>
</div>
</div>
<?php
}
/**
* Render select field.
*/
private function render_select( $options, $section, $key, $label, $choices, $description = '' ) {
$value = $this->field_value( $options, $section, $key );
?>
<div class="rx-field">
<label for="<?php echo esc_attr( $section . '_' . $key ); ?>"><?php echo esc_html( $label ); ?></label>
<div>
<select
class="rx-select"
id="<?php echo esc_attr( $section . '_' . $key ); ?>"
name="<?php echo esc_attr( $this->field_name( $section, $key ) ); ?>"
>
<?php foreach ( $choices as $choice_key => $choice_label ) : ?>
<option value="<?php echo esc_attr( $choice_key ); ?>" <?php selected( $value, $choice_key ); ?>>
<?php echo esc_html( $choice_label ); ?>
</option>
<?php endforeach; ?>
</select>
<?php if ( $description ) : ?>
<p class="rx-field-description"><?php echo esc_html( $description ); ?></p>
<?php endif; ?>
</div>
</div>
<?php
}
/**
* Render color field.
*/
private function render_color( $options, $section, $key, $label, $description = '' ) {
$value = $this->field_value( $options, $section, $key );
?>
<div class="rx-field">
<label for="<?php echo esc_attr( $section . '_' . $key ); ?>"><?php echo esc_html( $label ); ?></label>
<div>
<input
class="rx-color-picker"
type="text"
id="<?php echo esc_attr( $section . '_' . $key ); ?>"
name="<?php echo esc_attr( $this->field_name( $section, $key ) ); ?>"
value="<?php echo esc_attr( $value ); ?>"
data-default-color="<?php echo esc_attr( $value ); ?>"
/>
<?php if ( $description ) : ?>
<p class="rx-field-description"><?php echo esc_html( $description ); ?></p>
<?php endif; ?>
</div>
</div>
<?php
}
private function panel_general( $options ) {
?>
<section id="rx-general" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'General Settings', 'rx-theme' ); ?></h2>
<?php
$this->render_checkbox( $options, 'general', 'enable_theme_panel', 'Enable Theme Panel', 'Turn the Rx Theme admin panel features on or off.' );
$this->render_checkbox( $options, 'general', 'enable_back_to_top', 'Back To Top Button', 'Show a floating back-to-top button.' );
$this->render_checkbox( $options, 'general', 'enable_breadcrumbs', 'Breadcrumbs', 'Enable breadcrumb navigation.' );
$this->render_checkbox( $options, 'general', 'enable_reading_time', 'Reading Time', 'Show estimated reading time in posts.' );
$this->render_checkbox( $options, 'general', 'enable_post_views', 'Post Views', 'Enable basic post view tracking.' );
$this->render_checkbox( $options, 'general', 'enable_ajax_search', 'Ajax Search', 'Enable live search UI if your theme supports it.' );
$this->render_checkbox( $options, 'general', 'enable_smooth_scroll', 'Smooth Scroll', 'Enable smooth scrolling behavior.' );
$this->render_checkbox( $options, 'general', 'enable_lazyload', 'Lazy Load Images', 'Enable theme-level lazy loading support.' );
$this->render_checkbox( $options, 'general', 'enable_dark_mode_toggle', 'Dark Mode Toggle', 'Enable frontend dark mode switch if supported.' );
$this->render_textarea( $options, 'general', 'admin_footer_text', 'Admin Footer Text', 'Custom text for admin footer.' );
?>
</section>
<?php
}
private function panel_layout( $options ) {
?>
<section id="rx-layout" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'Layout Settings', 'rx-theme' ); ?></h2>
<?php
$this->render_text( $options, 'layout', 'site_width', 'Site Width', 'Example: 1200' );
$this->render_text( $options, 'layout', 'content_width', 'Content Width', 'Example: 760' );
$this->render_text( $options, 'layout', 'sidebar_width', 'Sidebar Width', 'Example: 320' );
$layouts = array(
'right-sidebar' => 'Right Sidebar',
'left-sidebar' => 'Left Sidebar',
'no-sidebar' => 'No Sidebar',
'full-width' => 'Full Width',
);
$this->render_select( $options, 'layout', 'global_layout', 'Global Layout', $layouts );
$this->render_select( $options, 'layout', 'single_layout', 'Single Post Layout', $layouts );
$this->render_select( $options, 'layout', 'page_layout', 'Page Layout', $layouts );
$this->render_select(
$options,
'layout',
'archive_layout',
'Archive Layout',
array(
'list' => 'List',
'grid' => 'Grid',
'masonry' => 'Masonry',
)
);
$this->render_checkbox( $options, 'layout', 'sticky_header', 'Sticky Header' );
$this->render_checkbox( $options, 'layout', 'transparent_header', 'Transparent Header' );
$this->render_checkbox( $options, 'layout', 'boxed_layout', 'Boxed Layout' );
?>
</section>
<?php
}
private function panel_colors( $options ) {
?>
<section id="rx-colors" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'Color Settings', 'rx-theme' ); ?></h2>
<?php
$this->render_color( $options, 'colors', 'primary_color', 'Primary Color' );
$this->render_color( $options, 'colors', 'secondary_color', 'Secondary Color' );
$this->render_color( $options, 'colors', 'accent_color', 'Accent Color' );
$this->render_color( $options, 'colors', 'body_bg_color', 'Body Background Color' );
$this->render_color( $options, 'colors', 'body_text_color', 'Body Text Color' );
$this->render_color( $options, 'colors', 'heading_color', 'Heading Color' );
$this->render_color( $options, 'colors', 'link_color', 'Link Color' );
$this->render_color( $options, 'colors', 'link_hover_color', 'Link Hover Color' );
$this->render_color( $options, 'colors', 'header_bg_color', 'Header Background Color' );
$this->render_color( $options, 'colors', 'footer_bg_color', 'Footer Background Color' );
$this->render_color( $options, 'colors', 'footer_text_color', 'Footer Text Color' );
?>
</section>
<?php
}
private function panel_typography( $options ) {
$fonts = array(
'system' => 'System Font',
'arial' => 'Arial',
'georgia' => 'Georgia',
'verdana' => 'Verdana',
'inter' => 'Inter',
'roboto' => 'Roboto',
'open-sans' => 'Open Sans',
'lato' => 'Lato',
'poppins' => 'Poppins',
'montserrat' => 'Montserrat',
);
?>
<section id="rx-typography" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'Typography Settings', 'rx-theme' ); ?></h2>
<?php
$this->render_select( $options, 'typography', 'body_font_family', 'Body Font Family', $fonts );
$this->render_select( $options, 'typography', 'heading_font_family', 'Heading Font Family', $fonts );
$this->render_text( $options, 'typography', 'body_font_size', 'Body Font Size', 'Example: 16' );
$this->render_text( $options, 'typography', 'body_line_height', 'Body Line Height', 'Example: 1.7' );
$this->render_text( $options, 'typography', 'heading_line_height', 'Heading Line Height', 'Example: 1.25' );
$this->render_text( $options, 'typography', 'paragraph_margin_bottom', 'Paragraph Bottom Margin', 'Example: 18' );
$this->render_checkbox( $options, 'typography', 'enable_font_preload', 'Enable Font Preload' );
$this->render_text( $options, 'typography', 'font_preload_url_1', 'Font Preload URL 1', '', 'url' );
$this->render_text( $options, 'typography', 'font_preload_url_2', 'Font Preload URL 2', '', 'url' );
$this->render_text( $options, 'typography', 'font_preload_url_3', 'Font Preload URL 3', '', 'url' );
?>
</section>
<?php
}
private function panel_seo( $options ) {
?>
<section id="rx-seo" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'SEO & Schema Settings', 'rx-theme' ); ?></h2>
<?php
$this->render_checkbox( $options, 'seo', 'enable_schema', 'Enable Basic Schema' );
$this->render_checkbox( $options, 'seo', 'enable_article_schema', 'Enable Article Schema' );
$this->render_checkbox( $options, 'seo', 'enable_breadcrumb_schema', 'Enable Breadcrumb Schema' );
$this->render_checkbox( $options, 'seo', 'enable_open_graph', 'Enable Open Graph' );
$this->render_checkbox( $options, 'seo', 'enable_twitter_cards', 'Enable Twitter Cards' );
$this->render_checkbox( $options, 'seo', 'enable_meta_description', 'Enable Meta Description' );
$this->render_checkbox( $options, 'seo', 'enable_canonical_url', 'Enable Canonical URL' );
$this->render_checkbox( $options, 'seo', 'enable_author_meta', 'Enable Author Meta' );
$this->render_checkbox( $options, 'seo', 'enable_updated_date', 'Enable Updated Date Meta' );
$this->render_text( $options, 'seo', 'default_og_image', 'Default Open Graph Image URL', '', 'url' );
$this->render_text( $options, 'seo', 'twitter_username', 'Twitter/X Username', 'Without @ symbol.' );
?>
</section>
<?php
}
private function panel_performance( $options ) {
?>
<section id="rx-performance" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'Performance Settings', 'rx-theme' ); ?></h2>
<?php
$this->render_checkbox( $options, 'performance', 'disable_emojis', 'Disable Emojis' );
$this->render_checkbox( $options, 'performance', 'disable_embeds', 'Disable Embeds' );
$this->render_checkbox( $options, 'performance', 'disable_dashicons_front', 'Disable Dashicons On Frontend' );
$this->render_checkbox( $options, 'performance', 'remove_wp_version', 'Remove WP Version' );
$this->render_checkbox( $options, 'performance', 'remove_shortlink', 'Remove Shortlink' );
$this->render_checkbox( $options, 'performance', 'remove_rsd_link', 'Remove RSD Link' );
$this->render_checkbox( $options, 'performance', 'remove_wlwmanifest', 'Remove WLW Manifest' );
$this->render_checkbox( $options, 'performance', 'defer_js', 'Defer JavaScript' );
$this->render_checkbox( $options, 'performance', 'async_js', 'Async JavaScript' );
$this->render_checkbox( $options, 'performance', 'preload_main_css', 'Preload Main CSS' );
$this->render_checkbox( $options, 'performance', 'preconnect_google_fonts', 'Preconnect Google Fonts' );
$this->render_textarea( $options, 'performance', 'dns_prefetch_urls', 'DNS Prefetch URLs', 'One URL per line. Example: //fonts.googleapis.com' );
$this->render_textarea( $options, 'performance', 'preconnect_urls', 'Preconnect URLs', 'One URL per line. Example: https://fonts.gstatic.com' );
$this->render_textarea( $options, 'performance', 'preload_urls', 'Preload URLs', 'One URL per line.' );
$this->render_checkbox( $options, 'performance', 'enable_local_cache_hint', 'Enable Local Cache Hint' );
?>
</section>
<?php
}
private function panel_security( $options ) {
?>
<section id="rx-security" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'Security Settings', 'rx-theme' ); ?></h2>
<?php
$this->render_checkbox( $options, 'security', 'disable_xmlrpc', 'Disable XML-RPC' );
$this->render_checkbox( $options, 'security', 'disable_rest_user_enum', 'Disable REST User Enumeration' );
$this->render_checkbox( $options, 'security', 'remove_login_errors', 'Remove Login Error Details' );
$this->render_checkbox( $options, 'security', 'disable_file_edit', 'Disable File Editing Constant Helper' );
$this->render_checkbox( $options, 'security', 'disable_author_archives', 'Disable Author Archives' );
$this->render_checkbox( $options, 'security', 'add_security_headers', 'Add Basic Security Headers' );
$this->render_checkbox( $options, 'security', 'disable_feed', 'Disable RSS Feeds' );
?>
</section>
<?php
}
private function panel_blog( $options ) {
?>
<section id="rx-blog" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'Blog Settings', 'rx-theme' ); ?></h2>
<?php
$this->render_checkbox( $options, 'blog', 'enable_related_posts', 'Enable Related Posts' );
$this->render_text( $options, 'blog', 'related_posts_count', 'Related Posts Count', 'Example: 4' );
$this->render_select(
$options,
'blog',
'related_posts_by',
'Related Posts By',
array(
'category' => 'Category',
'tag' => 'Tag',
'author' => 'Author',
'random' => 'Random',
)
);
$this->render_checkbox( $options, 'blog', 'enable_author_box', 'Enable Author Box' );
$this->render_checkbox( $options, 'blog', 'enable_social_share', 'Enable Social Share' );
$this->render_checkbox( $options, 'blog', 'enable_post_navigation', 'Enable Post Navigation' );
$this->render_checkbox( $options, 'blog', 'enable_table_of_contents', 'Enable Table of Contents' );
$this->render_text( $options, 'blog', 'excerpt_length', 'Excerpt Length', 'Example: 28' );
$this->render_text( $options, 'blog', 'archive_posts_per_row', 'Archive Posts Per Row', 'Example: 3' );
$this->render_checkbox( $options, 'blog', 'show_featured_image', 'Show Featured Image' );
$this->render_checkbox( $options, 'blog', 'show_category', 'Show Category' );
$this->render_checkbox( $options, 'blog', 'show_tags', 'Show Tags' );
$this->render_checkbox( $options, 'blog', 'show_date', 'Show Date' );
$this->render_checkbox( $options, 'blog', 'show_author', 'Show Author' );
$this->render_checkbox( $options, 'blog', 'show_comments_count', 'Show Comments Count' );
?>
</section>
<?php
}
private function panel_social( $options ) {
?>
<section id="rx-social" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'Social Settings', 'rx-theme' ); ?></h2>
<?php
$this->render_text( $options, 'social', 'facebook_url', 'Facebook URL', '', 'url' );
$this->render_text( $options, 'social', 'twitter_url', 'Twitter/X URL', '', 'url' );
$this->render_text( $options, 'social', 'linkedin_url', 'LinkedIn URL', '', 'url' );
$this->render_text( $options, 'social', 'youtube_url', 'YouTube URL', '', 'url' );
$this->render_text( $options, 'social', 'instagram_url', 'Instagram URL', '', 'url' );
$this->render_text( $options, 'social', 'pinterest_url', 'Pinterest URL', '', 'url' );
$this->render_text( $options, 'social', 'tiktok_url', 'TikTok URL', '', 'url' );
$this->render_text( $options, 'social', 'github_url', 'GitHub URL', '', 'url' );
$this->render_text( $options, 'social', 'whatsapp_number', 'WhatsApp Number', 'Example: +8801XXXXXXXXX' );
$this->render_text( $options, 'social', 'telegram_url', 'Telegram URL', '', 'url' );
?>
</section>
<?php
}
private function panel_header_footer( $options ) {
?>
<section id="rx-header-footer" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'Header, Footer & Custom Code', 'rx-theme' ); ?></h2>
<?php
$this->render_textarea( $options, 'header_footer', 'header_html', 'Header HTML', 'Code added inside wp_head if your functions file outputs it.', true );
$this->render_textarea( $options, 'header_footer', 'footer_html', 'Footer HTML', 'Code added inside footer area if your theme outputs it.', true );
$this->render_textarea( $options, 'header_footer', 'before_body_close_html', 'Before Body Close HTML', 'Code added before closing body tag.', true );
$this->render_textarea( $options, 'header_footer', 'custom_css', 'Custom CSS', 'CSS only. Do not add <style> tag.', true );
$this->render_textarea( $options, 'header_footer', 'custom_js', 'Custom JS', 'JavaScript only. Do not add <script> tag.', true );
$this->render_textarea( $options, 'header_footer', 'analytics_code', 'Analytics Code', 'Google Analytics, Tag Manager, or tracking code.', true );
$this->render_textarea( $options, 'header_footer', 'adsense_code', 'AdSense Code', 'Paste AdSense code if needed.', true );
$this->render_textarea( $options, 'header_footer', 'verification_meta', 'Verification Meta Tags', 'Google, Bing, Pinterest, Yandex verification tags.', true );
?>
</section>
<?php
}
private function panel_advanced( $options ) {
?>
<section id="rx-advanced" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'Advanced Settings', 'rx-theme' ); ?></h2>
<?php
$this->render_checkbox( $options, 'advanced', 'enable_debug_info', 'Enable Debug Info' );
$this->render_checkbox( $options, 'advanced', 'enable_safe_mode', 'Enable Safe Mode' );
$this->render_checkbox( $options, 'advanced', 'enable_custom_body_class', 'Enable Custom Body Classes' );
$this->render_textarea( $options, 'advanced', 'custom_body_classes', 'Custom Body Classes', 'Separate classes by space.' );
$this->render_checkbox( $options, 'advanced', 'custom_post_types_support', 'Custom Post Types Support' );
$this->render_checkbox( $options, 'advanced', 'maintenance_mode', 'Maintenance Mode' );
$this->render_textarea( $options, 'advanced', 'maintenance_message', 'Maintenance Message' );
?>
</section>
<?php
}
private function panel_tools() {
?>
<section id="rx-tools" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'Theme Tools', 'rx-theme' ); ?></h2>
<form method="post" enctype="multipart/form-data">
<?php wp_nonce_field( self::NONCE_ACTION, self::NONCE_NAME ); ?>
<h3><?php esc_html_e( 'Export Settings', 'rx-theme' ); ?></h3>
<p><?php esc_html_e( 'Download your Rx Theme settings as a JSON backup file.', 'rx-theme' ); ?></p>
<p>
<button type="submit" name="rx_theme_export_options" class="button button-secondary">
<?php esc_html_e( 'Export Settings', 'rx-theme' ); ?>
</button>
</p>
<hr>
<h3><?php esc_html_e( 'Import Settings', 'rx-theme' ); ?></h3>
<p><?php esc_html_e( 'Upload a previously exported Rx Theme JSON file.', 'rx-theme' ); ?></p>
<p class="rx-tools-row">
<input type="file" name="rx_theme_import_file" accept="application/json,.json">
<button type="submit" name="rx_theme_import_options" class="button button-secondary">
<?php esc_html_e( 'Import Settings', 'rx-theme' ); ?>
</button>
</p>
<hr>
<div class="rx-admin-panel rx-danger-zone">
<h3><?php esc_html_e( 'Reset Settings', 'rx-theme' ); ?></h3>
<p><?php esc_html_e( 'This will reset all Rx Theme options to default values.', 'rx-theme' ); ?></p>
<button type="submit" name="rx_theme_reset_options" class="button button-danger rx-confirm-reset">
<?php esc_html_e( 'Reset All Settings', 'rx-theme' ); ?>
</button>
</div>
</form>
</section>
<?php
}
private function panel_status() {
global $wpdb;
$active_plugins = get_option( 'active_plugins', array() );
$theme = wp_get_theme();
?>
<section id="rx-status" class="rx-admin-panel" data-panel>
<h2><?php esc_html_e( 'System Status', 'rx-theme' ); ?></h2>
<table class="widefat striped rx-system-table">
<tbody>
<tr>
<th><?php esc_html_e( 'Site URL', 'rx-theme' ); ?></th>
<td><?php echo esc_html( site_url() ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Home URL', 'rx-theme' ); ?></th>
<td><?php echo esc_html( home_url() ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Theme Name', 'rx-theme' ); ?></th>
<td><?php echo esc_html( $theme->get( 'Name' ) ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Theme Version', 'rx-theme' ); ?></th>
<td><?php echo esc_html( $theme->get( 'Version' ) ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'WordPress Version', 'rx-theme' ); ?></th>
<td><?php echo esc_html( get_bloginfo( 'version' ) ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'PHP Version', 'rx-theme' ); ?></th>
<td><?php echo esc_html( PHP_VERSION ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'MySQL Version', 'rx-theme' ); ?></th>
<td><?php echo esc_html( $wpdb->db_version() ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Memory Limit', 'rx-theme' ); ?></th>
<td><?php echo esc_html( WP_MEMORY_LIMIT ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Debug Mode', 'rx-theme' ); ?></th>
<td><?php echo defined( 'WP_DEBUG' ) && WP_DEBUG ? esc_html__( 'Enabled', 'rx-theme' ) : esc_html__( 'Disabled', 'rx-theme' ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Environment Type', 'rx-theme' ); ?></th>
<td><?php echo esc_html( wp_get_environment_type() ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Active Plugins', 'rx-theme' ); ?></th>
<td><?php echo esc_html( is_array( $active_plugins ) ? count( $active_plugins ) : 0 ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Multisite', 'rx-theme' ); ?></th>
<td><?php echo is_multisite() ? esc_html__( 'Yes', 'rx-theme' ) : esc_html__( 'No', 'rx-theme' ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Language', 'rx-theme' ); ?></th>
<td><?php echo esc_html( get_locale() ); ?></td>
</tr>
<tr>
<th><?php esc_html_e( 'Timezone', 'rx-theme' ); ?></th>
<td><?php echo esc_html( wp_timezone_string() ); ?></td>
</tr>
</tbody>
</table>
</section>
<?php
}
/**
* Placeholder quick links filter.
*/
public function theme_admin_quick_links( $links, $file ) {
return $links;
}
}
endif;
/**
* Boot admin page.
*/
new Rx_Theme_Admin_Page();
/**
* Helper function for theme files.
*
* Usage:
* rx_theme_get_option( 'colors', 'primary_color' );
*/
if ( ! function_exists( 'rx_theme_get_option' ) ) {
function rx_theme_get_option( $section, $key, $default = null ) {
return Rx_Theme_Admin_Page::get_option( $section, $key, $default );
}
}
Now include it in your functions.php:
/**
* Rx Theme Admin Page.
*/
require_once get_template_directory() . '/inc/admin/admin-page.php';
To actually output saved custom CSS / JS / header codes on the frontend, also add this helper file later or add these hooks in functions.php:
/**
* Output Rx Theme custom CSS.
*/
add_action( 'wp_head', function () {
$custom_css = rx_theme_get_option( 'header_footer', 'custom_css', '' );
if ( ! empty( $custom_css ) ) {
echo '<style id="rx-theme-custom-css">' . wp_strip_all_tags( $custom_css ) . '</style>';
}
$header_html = rx_theme_get_option( 'header_footer', 'header_html', '' );
$analytics_code = rx_theme_get_option( 'header_footer', 'analytics_code', '' );
$verification_meta = rx_theme_get_option( 'header_footer', 'verification_meta', '' );
if ( ! empty( $verification_meta ) ) {
echo wp_kses_post( $verification_meta );
}
if ( ! empty( $header_html ) ) {
echo wp_kses_post( $header_html );
}
if ( ! empty( $analytics_code ) ) {
echo wp_kses_post( $analytics_code );
}
}, 99 );
/**
* Output Rx Theme footer code.
*/
add_action( 'wp_footer', function () {
$footer_html = rx_theme_get_option( 'header_footer', 'footer_html', '' );
$before_body_close_html = rx_theme_get_option( 'header_footer', 'before_body_close_html', '' );
$custom_js = rx_theme_get_option( 'header_footer', 'custom_js', '' );
$adsense_code = rx_theme_get_option( 'header_footer', 'adsense_code', '' );
if ( ! empty( $footer_html ) ) {
echo wp_kses_post( $footer_html );
}
if ( ! empty( $adsense_code ) ) {
echo wp_kses_post( $adsense_code );
}
if ( ! empty( $custom_js ) ) {
echo '<script id="rx-theme-custom-js">' . wp_kses_post( $custom_js ) . '</script>';
}
if ( ! empty( $before_body_close_html ) ) {
echo wp_kses_post( $before_body_close_html );
}
}, 99 );
After adding, go to:
WordPress Dashboard → Appearance → Rx Theme
There you will see your full advanced Rx Theme admin panel.