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