3 Plugin Name: Sample Admin Page
4 Plugin URI: http://yourls.org/
5 Description: A example of a plugin administration page to save user defined option
8 Author URI: http://ozh.org/
12 if( !defined( 'YOURLS_ABSPATH' ) ) die();
14 // Register our plugin admin page
15 yourls_add_action( 'plugins_loaded', 'ozh_yourls_samplepage_add_page' );
16 function ozh_yourls_samplepage_add_page() {
17 yourls_register_plugin_page( 'sample_page', 'Sample Admin Page', 'ozh_yourls_samplepage_do_page' );
18 // parameters: page slug, page title, and function that will display the page itself
22 function ozh_yourls_samplepage_do_page() {
24 // Check if a form was submitted
25 if( isset( $_POST['test_option'] ) ) {
27 yourls_verify_nonce( 'sample_page' );
30 ozh_yourls_samplepage_update_option();
33 // Get value from database
34 $test_option = yourls_get_option( 'test_option' );
37 $nonce = yourls_create_nonce( 'sample_page' );
40 <h2>Sample Plugin Administration Page</h2>
41 <p>This plugin stores an integer in the option database</p>
43 <input type="hidden" name="nonce" value="$nonce" />
44 <p><label for="test_option">Enter an integer</label> <input type="text" id="test_option" name="test_option" value="$test_option" /></p>
45 <p><input type="submit" value="Update value" /></p>
51 // Update option in database
52 function ozh_yourls_samplepage_update_option() {
53 $in = $_POST['test_option'];
56 // Validate test_option. ALWAYS validate and sanitize user input.
57 // Here, we want an integer
60 // Update value in database
61 yourls_update_option( 'test_option', $in );