我做了一项大规模的研究。但我什么都不想要。我想在静态样式文件中设置选项页面的样式。我该怎么做?
Sources
/*
*Create A Simple Theme Options Panel
*Exit if accessed directly
*/
if (!defined(\'ABSPATH\')){
exit;
}
// Start Class
if ( ! class_exists(\'Azura_Theme_Options\')){
class Azura_Theme_Options{
public function __construct(){
// We only need to register the admin panel on the back-end
if (is_admin()){
add_action(\'admin_menu\', array( \'Azura_Theme_Options\', \'add_admin_menu\'));
add_action(\'admin_init\', array( \'Azura_Theme_Options\', \'register_settings\'));
}
}
public static function get_theme_options() {
return get_option(\'theme_options\');
}
public static function get_theme_option($id) {
$options = self::get_theme_options();
if (isset($options[$id])){
return $options[$id];
}
}
// Add sub menu page
public static function add_admin_menu(){
add_menu_page(
esc_html__(\'Azura Panel\', \'text-domain\'),
esc_html__(\'Azura Panel\', \'text-domain\'),
\'manage_options\',
\'azura-panel\',
array(\'Azura_Theme_Options\', \'create_admin_page\')
);
}
/**
* Register a setting and its sanitization callback.
* We are only registering 1 setting so we can store all options in a single option as
* an array. You could, however, register a new setting for each option
*/
public static function register_settings(){
register_setting(\'theme_options\', \'theme_options\', array( \'Azura_Theme_Options\', \'sanitize\'));
}
// Sanitization callback
public static function sanitize($options){
// If we have options lets sanitize them
if ($options){
// Input
if (!empty($options[\'site_name\'])){
$options[\'site_name\'] = sanitize_text_field( $options[\'site_name\'] );
}else{
unset($options[\'site_name\']); // Remove from options if empty
}
// Select
if (!empty($options[\'select_example\'])){
$options[\'select_example\'] = sanitize_text_field( $options[\'select_example\'] );
}
}
// Return sanitized options
return $options;
}
/**
* Settings page output
*/
public static function create_admin_page(){ ?>
<div class="wrap">
<h1><?php esc_html_e(\'Tema Ayarları\', \'text-domain\'); ?></h1>
<form method="post" action="options.php">
<?php settings_fields(\'theme_options\'); ?>
<table class="form-table wpex-custom-admin-login-table">
<?php // Text input example ?>
<tr valign="top">
<th scope="row"><?php esc_html_e(\'Başlık\', \'text-domain\'); ?></th>
<td>
<?php $value = self::get_theme_option(\'site_name\'); ?>
<input type="text" name="theme_options[site_name]" value="<?php echo esc_attr($value); ?>">
</td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e(\'Açıklama\', \'text-domain\'); ?></th>
<td>
<?php $value = self::get_theme_option(\'site_desc\'); ?>
<input type="text" name="theme_options[site_desc]" value="<?php echo esc_attr($value); ?>">
</td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e(\'Buton\', \'text-domain\'); ?></th>
<td>
<?php $value = self::get_theme_option(\'top_header_btn\'); ?>
<input type="text" name="theme_options[top_header_btn]" value="<?php echo esc_attr($value); ?>">
</td>
</tr>
<tr valign="top">
<th scope="row"><?php esc_html_e(\'Buton Link\', \'text-domain\'); ?></th>
<td>
<?php $value = self::get_theme_option(\'top_header_btn_link\'); ?>
<input type="text" name="theme_options[top_header_btn_link]" value="<?php echo esc_attr($value); ?>">
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div><!-- .wrap -->
<?php }
}
}
new Azura_Theme_Options();
// Helper function to use in your theme to return a theme option value
function myprefix_get_theme_option( $id = \'\' ) {
return Azura_Theme_Options::get_theme_option( $id );
}