Last active
August 29, 2021 13:15
-
-
Save wahengchang/ed451545beab136a52625342c9f23f99 to your computer and use it in GitHub Desktop.
This is an example of developing a plugin. to read more: https://peter-chang.medium.com/3-wordpress-hook-mechanism-and-principle-filter-ad8b079e37e8
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 | |
/** | |
* @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