'Header Widget Area',
'id' => 'header-widget-area',
'description' => 'Add widgets here to appear in your header.',
'before_widget' => '
',
'after_widget' => '
',
'before_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' => '',
) );
// 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' => '',
) );
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' => '',
) );
// 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' => '',
) );
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' => '',
) );
}
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']) : "",
];
$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(
'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'));
}
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 = [
'devmin_general' => [
'site_title' => '',
'site_description' => '',
'logo' => '',
],
'socials' => [
'facebook' => '',
'x' => '',
'youtube' => '',
'instagram' => '',
'github' => '',
'stackoverflow' => '',
]
];
}
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() {
wp_enqueue_script('bootstrap', get_theme_file_uri() . '/assets/bootstrap.min.js', array('jquery'), null, true);
wp_enqueue_script('popper', get_theme_file_uri() . '/assets/popper.min.js', array('jquery'), 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 = '') {
global $devmin_theme_options;
if (empty($searched))
return '';
if (empty($devmin_theme_options))
$devmin_theme_options = get_option('devmin_theme_options');
$searched = explode('.', $searched);
$result = $devmin_theme_options;
foreach ($searched as $key) {
if (!isset($result[$key])) {
return '';
}
$result = $result[$key];
}
return $result;
}
public static function get_icon($name = '')
{
$socialicons = [
'facebook' => ' ',
'x' => ' ',
'youtube' => ' ',
'github' => ' ',
'instagram' => ' ',
'stackoverflow' => ' '
];
return $socialicons[$name] ?? $name;
}
}
$k = new Devmin();