Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Register your settings (this goes in your plugin file or
- // if registering theme options, in your functions.php file
- function register_my_plugin_options()
- {
- register_setting( 'my_plugin_options', 'my_plugin_options', 'my_plugin_validation_cb' );
- add_settings_section( 'my_plugin_main', 'Main Plugin Options', 'my_plugin_main_settings', 'my_plugin_slug' );
- add_settings_field( 'send-email-to', 'Send email notices to:', 'my_plugin_main_email_input', 'my_plugin_main', 'my_plugin_slug' );
- }
- add_action( 'admin_init', 'register_my_plugin_options' );
- function my_plugin_main_settings()
- {
- // do stuff here
- }
- function my_plugin_main_email_input()
- {
- // you would output your form field here
- }
- // Function for validating all your various settings
- function my_plugin_validation_cb( $input )
- {
- $valid = array();
- $options = get_option( 'my_plugin_options' );
- if( $input['send-email-to'] != sanitize_email( $input['send-email-to'] ) )
- {
- add_settings_error(
- 'send-email-to',
- 'send-email-field-error',
- "You supplied an invalid email address!",
- 'error'
- );
- } else {
- $valid['send-email-to'] = $input['send-email-to'];
- }
- return $valid;
- }
- // Example function that would render your options page content
- function render_my_plugin_options_page()
- {
- ?>
- <div class="wrap">
- <h2>My Plugin Options</h2>
- <?php // IMPORTANT!!! If you want your settings fields to display errors,
- // Call settings errors here!
- settings_errors(); ?>
- <?php
- // echo out the form and other settings info here
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement