Skip to content

Instantly share code, notes, and snippets.

@frontend-coder
Last active June 1, 2022 10:37
Show Gist options
  • Save frontend-coder/469b60a573546972d56005a6e1929237 to your computer and use it in GitHub Desktop.
Save frontend-coder/469b60a573546972d56005a6e1929237 to your computer and use it in GitHub Desktop.
25, Дадаю поля в панель с опціями #wordpress
function test_add_admin_page() {
$hook_sufix = add_menu_page('Test Theme Option', 'Опції теми', 'manage_options', 'test-options', 'test_create_page',
'dashicons-admin-customizer', 81 );
// test-options - слаг
// 'dashicons-admin-customizer' or get_template_directory_uri().'/assets/img/moon.png'
add_action("admin_print_scripts-{$hook_sufix}", "test_admin_styles");
// визначаю фунцію, яка буде створювати поля опцій
add_action('admin_init','test_custom_setings');
//add_action('admin_enqueue_scripts', 'test_admin_styles');
}
function test_custom_setings() {
// зарестрував опцію в групі
register_setting('test_general_group', 'test_email');
// зарестрував секцію в групі
add_settings_section('test_general_section', 'Секція з опціями', function() {echo '<p>Опис секції або блока</p>';}, 'test-options');
add_settings_field('field_1', 'E-mail', test_options_fun, 'test-options', 'test_general_section', array('label_for' => 'field_1' ));
}
function test_options_fun() {
$test_e = esc_attr(get_option('test_email'));
echo '<input type="email" name="test_email" class="reg_text" id="field_1" value="'. $test_e .'"><p class="descriptions"> Опис поля </p>';
}
function test_create_page() {
// функція, яка створює сторінку зі всіма елементами
?>
<div class="wrap">
<h3>Опції теми</h3>
<?php settings_errors(); ?>
<form sction="options.php" method="post">
<?php settings_fields('test_general_group'); ?>
<?php do_settings_sections('test_options'); ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}
add_action('admin_menu', 'test_add_admin_page');
як підєднати стілі до адмінки
function test_admin_styles() {
wp_enqueue_style('test-admin-style', get_template_directory_uri().'/assets/css/admin-style.php');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment