'Header Widget Area', 'id' => 'header-widget-area', 'description' => 'Add widgets here to appear in your header.', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => 'Footer Widget Area', 'id' => 'footer-widget-area', 'description' => 'Add widgets here to appear in your footer.', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); // before the front/index page register_sidebar( array( 'name' => 'Before Index Widget Area', 'id' => 'before-index-widget-area', 'description' => 'Add widgets here to appear before the index.', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => 'After Index Widget Area', 'id' => 'after-index-widget-area', 'description' => 'Add widgets here to appear after the index template.', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); // before the single post register_sidebar( array( 'name' => 'Before Single Post Widget Area', 'id' => 'before-single-post-widget-area', 'description' => 'Add widgets here to appear before the single post.', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => 'After Single Post Widget Area', 'id' => 'after-single-post-widget-area', 'description' => 'Add widgets here to appear after the single post.', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } function save_theme_options() { if( !isset( $_POST['action'] ) || $_POST['action'] != 'save_devmin_theme_options') return; $settings = []; $settings['general'] = [ 'site_title' => !empty($_POST['general']['site_title']) ? sanitize_text_field($_POST['general']['site_title']) : "", 'site_description' => !empty($_POST['general']['site_description']) ? sanitize_text_field($_POST['general']['site_description']) : "", 'logo' => !empty($_POST['general']['logo']) ? esc_url($_POST['general']['logo']) : "", 'primarycolor' => !empty($_POST['general']['primarycolor']) ? sanitize_text_field($_POST['general']['primarycolor']) : "", ]; $settings['socials'] = [ 'facebook' => !empty($_POST['socials']['facebook']) ? esc_url($_POST['socials']['facebook']) : "", 'x' => !empty($_POST['socials']['x']) ? esc_url($_POST['socials']['x']) : "", 'youtube' => !empty($_POST['socials']['youtube']) ? esc_url($_POST['socials']['youtube']) : "", 'instagram' => !empty($_POST['socials']['instagram']) ? esc_url($_POST['socials']['instagram']) : "", 'github' => !empty($_POST['socials']['github']) ? esc_url($_POST['socials']['github']) : "", 'stackoverflow' => !empty($_POST['socials']['stackoverflow']) ? esc_url($_POST['socials']['stackoverflow']) : "", ]; update_option('devmin_theme_options', $settings); // show a success message add_settings_error('devmin_theme_options', 'devmin_theme_options', 'Settings Saved', 'updated'); } public function register_menus() { register_nav_menus(array( 'devmin-primary-menu' => __('Primary Menu', 'devmin'), )); } public function theme_supports() { add_theme_support('title-tag'); add_theme_support('post-thumbnails'); add_theme_support('custom-logo'); add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption')); add_theme_support('post-formats', array('aside', 'image', 'video', 'quote', 'link', 'gallery', 'audio')); add_theme_support( 'automatic-feed-links' ); register_block_style('core/quote', [ 'name' => 'default', 'label' => 'Default', 'inline_style' => '.wp-block-quote.is-style-default { color: #007bff; }', ]); add_theme_support( 'wp-block-styles' ); add_theme_support( 'responsive-embeds' ); add_theme_support( 'align-wide' ); // add colors to the editor add_theme_support('editor-color-palette', [ [ 'name' => 'Primary', 'slug' => 'primary', 'color' => '#007bff', ], [ 'name' => 'Secondary', 'slug' => 'secondary', 'color' => '#6c757d', ], [ 'name' => 'Success', 'slug' => 'success', 'color' => '#28a745', ], [ 'name' => 'Danger', 'slug' => 'danger', 'color' => '#dc3545', ], [ 'name' => 'Warning', 'slug' => 'warning', 'color' => '#ffc107', ], [ 'name' => 'Info', 'slug' => 'info', 'color' => '#17a2b8', ], [ 'name' => 'Light', 'slug' => 'light', 'color' => '#f8f9fa', ], [ 'name' => 'Dark', 'slug' => 'dark', 'color' => '#343a40', ], ]); // add font sizes to the editor add_theme_support('editor-font-sizes', [ [ 'name' => 'Small', 'size' => 12, 'slug' => 'small', ], [ 'name' => 'Normal', 'size' => 16, 'slug' => 'normal', ], [ 'name' => 'Large', 'size' => 24, 'slug' => 'large', ], [ 'name' => 'Huge', 'size' => 36, 'slug' => 'huge', ], ]); } function add_theme_menu() { add_submenu_page('themes.php', 'Devmin Theme Options', 'Theme Options', 'manage_options', 'devmin-options', array($this, 'theme_options_page')); } static function get_default_options(){ return [ 'general' => [ 'site_title' => '', 'site_description' => '', 'logo' => '', 'primarycolor' => '', ], 'socials' => [ 'facebook' => '', 'x' => '', 'youtube' => '', 'instagram' => '', 'github' => '', 'stackoverflow' => '', ] ]; } function theme_options_page($page) { // load css for the admin page wp_enqueue_style('devmin-admin', get_template_directory_uri() . '/assets/admin-style.css'); $options = get_option('devmin_theme_options'); if( !$options ) { $options = $this->get_default_options(); } include_once __DIR__ . '/templates/theme-options.php'; } public function enqueue_styles() { wp_enqueue_style('devmin-style', get_stylesheet_uri()); wp_enqueue_style('bootstrap', get_theme_file_uri() . '/assets/bootstrap.min.css'); } public function enqueue_scripts() { // Enqueue Popper.js before Bootstrap wp_enqueue_script('popper', get_theme_file_uri() . '/assets/popper.min.js', array('jquery'), null, true); wp_enqueue_script('bootstrap', get_theme_file_uri() . '/assets/bootstrap.min.js', array('jquery', 'popper'), null, true); } /** * Function that returns the value of a specific option from the theme options using a dot-separated path. * @param string $searched * @return mixed */ public static function get_option($searched = '', $default = '') { global $devmin_theme_options; if (empty($searched)) return ''; if (empty($devmin_theme_options)){ $devmin_theme_options = get_option('devmin_theme_options'); if (empty($devmin_theme_options)) { return $default; } } $searched = explode('.', $searched); $result = $devmin_theme_options; foreach ($searched as $key) { if (!isset($result[$key])) { return $default; } $result = $result[$key]; } return $result; } public static function get_icon($name = '') { $socialicons = [ 'facebook' => '', 'x' => '', 'youtube' => '', 'github' => '', 'instagram' => '', 'stackoverflow' => '' ]; return $socialicons[$name] ?? $name; } public static function get_accent_color() { return self::get_option('general.primarycolor', '#007bff'); } public static function get_nav_link_color() { return self::get_adjusted_color(self::get_accent_color(), false, 100); } public static function get_nav_link_hover_color() { return self::get_adjusted_color(self::get_accent_color(), false, 10); } public static function get_header_text_color() { return self::get_adjusted_color(self::get_accent_color(), false, 20); } public static function get_sub_menu_background() { return self::get_adjusted_color(self::get_accent_color(), true, 30); } /** * Get a contrasting color or a darker shade of a given hex color. * * @param string $hexcolor The hex color code. * @param bool $darken Whether to return a darker shade. * @param int $percent The percentage to darken the color (if $darken is true). * @return string The contrasting or darkened color. */ public static function get_adjusted_color($hexcolor, $darken = false, $percent = 20) { // Remove the hash at the start if it's there $hexcolor = str_replace('#', '', $hexcolor); // Convert 3-digit hex to 6-digit hex if (strlen($hexcolor) === 3) { $hexcolor = str_repeat(substr($hexcolor, 0, 1), 2) . str_repeat(substr($hexcolor, 1, 1), 2) . str_repeat(substr($hexcolor, 2, 1), 2); } // Get the RGB values $r = hexdec(substr($hexcolor, 0, 2)); $g = hexdec(substr($hexcolor, 2, 2)); $b = hexdec(substr($hexcolor, 4, 2)); if ($darken) { // Darken each color component $r = max(0, min(255, $r - ($r * $percent / 100))); $g = max(0, min(255, $g - ($g * $percent / 100))); $b = max(0, min(255, $b - ($b * $percent / 100))); // Convert back to hex and return return sprintf("#%02x%02x%02x", $r, $g, $b); } else { // Calculate the luminance $luminance = (0.299 * $r + 0.587 * $g + 0.114 * $b) / 255; // Return black or white depending on the luminance return $luminance > 0.5 ? '#000000' : '#FFFFFF'; } } } $k = new Devmin();