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
11 // Register our plugin admin page
\r
12 yourls_add_action( 'plugins_loaded', 'ozh_yourls_samplepage_add_page' );
\r
13 function ozh_yourls_samplepage_add_page() {
\r
14 yourls_register_plugin_page( 'sample_page', 'Sample Admin Page', 'ozh_yourls_samplepage_do_page' );
\r
15 // parameters: page slug, page title, and function that will display the page itself
\r
18 // Display admin page
\r
19 function ozh_yourls_samplepage_do_page() {
\r
21 // Check if a form was submitted
\r
22 if( isset( $_POST['test_option'] ) )
\r
23 ozh_yourls_samplepage_update_option();
\r
25 // Get value from database
\r
26 $test_option = yourls_get_option( 'test_option' );
\r
29 <h2>Sample Plugin Administration Page</h2>
\r
30 <p>This plugin stores an integer in the option database</p>
\r
31 <form method="post">
\r
32 <p><label for="test_option">Enter an integer</label> <input type="text" id="test_option" name="test_option" value="$test_option" /></p>
\r
33 <p><input type="submit" value="Update value" /></p>
\r
38 // Update option in database
\r
39 function ozh_yourls_samplepage_update_option() {
\r
40 $in = $_POST['test_option'];
\r
43 // Validate test_option. ALWAYS validate and sanitize user input.
\r
44 // Here, we want an integer
\r
47 // Update value in database
\r
48 yourls_update_option( 'test_option', $in );
\r