Created
February 20, 2019 21:47
-
-
Save VasylKyryliuk/971526083b42b7ece314d1822ba1c7b6 to your computer and use it in GitHub Desktop.
Сторінка налаштувань (WP settings page)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Сторінка налаштувань | |
// create custom plugin settings menu | |
add_action('admin_menu', 'baw_create_menu'); | |
function baw_create_menu() | |
{ | |
//create new top-level menu | |
add_menu_page('Global Settings', 'Theme Settings', 'administrator', FILE, 'baw_settings_page', 'dashicons-admin-generic'); | |
//call register settings function | |
add_action('admin_init', 'register_mysettings'); | |
} | |
function register_mysettings() | |
{ | |
//register our settings | |
register_setting('baw-settings-group', 'fb_link'); | |
register_setting('baw-settings-group', 'vk_link'); | |
register_setting('baw-settings-group', 'in_link'); | |
register_setting('baw-settings-group', 'pn_link'); | |
} | |
function baw_settings_page() | |
{ | |
?> | |
<div class="wrap"> | |
<h2>Settings</h2> | |
<div class="setting"> | |
<form method="post" action="options.php"> | |
<?php settings_fields('baw-settings-group'); ?> | |
<table class="form-table"> | |
<tr valign="top"> | |
<th scope="row">Facebook link</th> | |
<td><input type="text" name="fb_link" style="width:65%" | |
value="<?php echo get_option('fb_link'); ?>"></td> | |
</tr> | |
<tr valign="top"> | |
<th scope="row">Vkontakte link</th> | |
<td><input type="text" name="vk_link" style="width:65%" | |
value="<?php echo get_option('vk_link'); ?>"></td> | |
</tr> | |
<tr valign="top"> | |
<th scope="row">Instagram link</th> | |
<td><input type="text" name="in_link" style="width:65%" | |
value="<?php echo get_option('in_link'); ?>"></td> | |
</tr> | |
<tr valign="top"> | |
<th scope="row">Pinterest link</th> | |
<td><input type="text" name="pn_link" style="width:65%" | |
value="<?php echo get_option('pn_link'); ?>"></td> | |
</tr> | |
</table> | |
<p class="submit"> | |
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>"/> | |
</p> | |
</form> | |
</div> | |
</div> | |
<?php | |
} | |
//вивід на фронті (front output) | |
<?php echo get_option('pn_link'); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment