-
-
Save yellowstonebum/543008819e3a8c372e7c1649a385051a to your computer and use it in GitHub Desktop.
Admin Form Page
This file contains 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
<?php | |
// 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 ( " | |
SELECT * | |
FROM $wpdb->wp_options | |
WHERE option_name = mfwp_settings | |
LIMIT 1 | |
" ); | |
$field1 = get_option( mfwp_settings ); | |
// Creating Admin Menu option | |
add_action('admin_menu', function () { | |
add_options_page( | |
//CHANGE | |
'My First Wordpress Plugin', //title browser | |
//CHANGE | |
'MFWP', //menu text | |
//KEEP | |
'manage_options', //require capability **KEEP AS manage_options** | |
//CHANGE | |
'mfwp_admin', //reference slug | |
//CHANGE | |
'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"> | |
<?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> | |
<p class="submit"> | |
<input type="submit" class="button-primary" value="<?php _e('Save Option', 'mfwp_domain'); ?>"> | |
</p> | |
</form> | |
</div> | |
<?php | |
//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