Skip to content

Instantly share code, notes, and snippets.

@wahengchang
Last active Aug 29, 2021
Embed
What would you like to do?
<?php
/**
* @package Dev-Plugin
* @version 1.7.2
*/
/*
Plugin Name: Dev Plugin
Plugin URI: http://wordpress.org/plugins/hello-dolly/
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page.
Author: Matt Mullenweg
Version: 1.7.2
Author URI: http://ma.tt/
*/
function adminMenuHandler() {
global $team_page;
add_menu_page( __( 'Teams', 'sports-bench' ), __( 'Teams', 'sports-bench' ), 'edit_posts', 'add_data', 'adminMenuPageHandler', 'dashicons-groups', 6 ) ;
}
function adminMenuPageHandler() {
settings_errors();
echo('<h1> Team Setting </h1>
<p> This is an example section of giving the information below, then save them into DB - option.</p>
<div>
<form method="post" action="options.php">
<label>Team Email: </label><input type="text" name="my_option_email" value="'.get_option('my_option_email').' " /><br />
<label>Team City: </label><input type="text" name="id_number" value="'.get_option('id_number').' " /><br />
<label>Team State: </label><input type="text" name="option_etc" value="'.get_option('option_etc').' " /><br />');
settings_fields('my_option_group');
do_settings_sections('my_option_group');
submit_button();
echo(' </form>
</div>');
}
add_action( 'admin_menu', 'adminMenuHandler' );
function register_mysettings() { // whitelist options
$args = array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => NULL,
);
function validation_email($input){
echo 'validation_email validation_email ';
/** Sanitize input */
$sanitized = sanitize_email( $input );
/** If output is different, input was wrong */
if ( $sanitized !== $input ) {
add_settings_error( 'my_option_email', 'your-error-code', '[INFO]'.$sanitized.'||'.$input);
}
/** Save the sanitized version */
return $sanitized;
}
register_setting(
'my_option_group', // Option group
'my_option_email', // Option name
'validation_email'
);
register_setting(
'my_option_group', // Option group
'id_number', // Option name
);
register_setting(
'my_option_group', // Option group
'option_etc', // Option name
);
}
add_action( 'admin_init', 'register_mysettings' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment