Skip to content

Instantly share code, notes, and snippets.


yellowstonebum/admin-page.php Secret

Last active Dec 19, 2018
What would you like to do?
Admin Form Page
// Initiate Global(s)
global $wpdb;
//TRIED to call normally via get_option, but it wouldn't fire
$test = get_option( 'mfwp_settings' );
//TRIED to call via SQL, but comes back as NULL
$get_settings = $wpdb->get_results ( "
FROM $wpdb->wp_options
WHERE option_name = mfwp_settings
" );
$field1 = get_option( mfwp_settings );
// Creating Admin Menu option
add_action('admin_menu', function () {
'My First Wordpress Plugin', //title browser
'MFWP', //menu text
'manage_options', //require capability **KEEP AS manage_options**
'mfwp_admin', //reference slug
'mfwp_options_page' //callback to menu body
// Call Back & create body - CHANGE prefix
function mfwp_options_page() {
//ob_start(); ?>
<div class="wrap">
<h2>My First WordPress Plugin Options</h2>
<form method="post" action="options.php">
settings_fields( 'mfwp_settings_group' );
<h4><?php _e('Placeholder for Plugin Fields', 'mfwp_domain'); ?></h4>
<p><?php echo $field1 . ' tester<br />'; echo var_dump($get_settings);?>
<label class="description" for="mfwp_settings"><?php _e('This is a label description', 'mfwp_domain'); ?></label>
<input class="regular-text" id="mfwp_settings" name="mfwp_settings" type="" value="<?php echo $test; ?>">
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Option', 'mfwp_domain'); ?>">
//echo ob_get_clean();
function mfwp_register_settings() {
$args = array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field', //Sanatizes data
'default' => NULL,
register_setting('mfwp_settings_group', 'mfwp_settings', $args);
add_action('admin_init', 'mfwp_register_settings');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment