Please write below code in functions.php
<?php
add_action('admin_menu', 'yt_menu');
function yt_menu() {
add_menu_page('YT Options', 'yt Uploader', 'manage_options', 'yt-identifier', 'yt_options_page', '', 30);
}
function yt_register_settings() {
register_setting( 'yt_theme_options', 'yt_options');
}
add_action( 'admin_init', 'yt_register_settings' );
/*
Above, we have simply created a new function for registering the new option (YT Options) using the register setting wordpress function. The most important part of the above code is the “add_menu_page” bit, which is the code that actually adds a new menu item to the admin panel named “YT Options”.
We have successfully created a new menu item, specifically for changing the text on YT Options. Now we need to create some content for this new page. Add the following code directly below what code you have already added:
*/
function yt_options_page() {
global $yt_options, $yt_categories, $yt_layouts;
if (!current_user_can('manage_options')) {
wp_die( __('You do not have sufficient permissions to access this page.') );
}
echo '<div class="wrap"><h2>Change your yt uploader settings</h2></div>';
?>
<form id="yt_auth_options" method="post" action="options.php">
<?php $settings = get_option( 'yt_options', $yt_options ); ?>
<?php settings_fields( 'yt_theme_options' ); ?>
<table class="form-table">
<tbody
<tr valign="top">
<td colspan="2">
<div id="auth_options">
<div>
Username : <label title="username"><input type="text" name="yt_options[username]" value="<?php echo stripslashes($settings['username']); ?>"></label>
<br>Password : <label title="password"><input type="password" name="yt_options[password]" value="<?php echo stripslashes($settings['password']); ?>"></label>
</div>
</div><br>
</td>
</tr>
</tbody>
</table>
<input type="submit" value="Save settings" class="button-primary"> <input type="hidden" value="1" name="yt_uploader_settings"></form>
<?php
}
?>
The code above first of all gives our new page a title that is in-keeping with the style of our admin area. Next up, we define what message to display when our text has been updated. We then create our form for actually entering and editing the options. We then validate the value of this text and return it to be stored, using options.php.
No comments:
Post a Comment