1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | |
---|
5 | Plugin Name: Dummy Plugin |
---|
6 | |
---|
7 | */ |
---|
8 | |
---|
9 | class DummyPlugin { |
---|
10 | |
---|
11 | var $options_page_handle; |
---|
12 | |
---|
13 | var $options_page = 'dummy_plugin'; |
---|
14 | var $option_group = 'dummy_plugin'; |
---|
15 | var $option_name = 'dp_example'; |
---|
16 | var $option_name_2 = 'dp_example_2'; |
---|
17 | var $settings_section = 'dp_general'; |
---|
18 | |
---|
19 | function __construct() { |
---|
20 | add_action( 'admin_init', array( &$this, 'dummy_plugin_init' ) ); |
---|
21 | add_action( 'admin_init', array( &$this, 'test_removal' ), 11); |
---|
22 | add_action( 'admin_menu', array( &$this, 'add_settings_page' ) ); |
---|
23 | } |
---|
24 | |
---|
25 | function dummy_plugin_init() { |
---|
26 | register_setting( $this->option_group, $this->option_name ); |
---|
27 | register_setting( $this->option_group, $this->option_name_2 ); |
---|
28 | |
---|
29 | add_settings_section( $this->settings_section, __( 'General Settings' ), array( &$this, 'settings_section_text' ), $this->options_page ); |
---|
30 | |
---|
31 | add_settings_field( $this->option_name, __( 'Example Setting' ), array( &$this, 'settings_field_input' ), $this->options_page, $this->settings_section, array( 'type' => $this->option_name ) ); |
---|
32 | |
---|
33 | add_settings_field( $this->option_name_2, __( 'Example Setting 2' ), array( &$this, 'settings_field_input' ), $this->options_page, $this->settings_section, array( 'type' => $this->option_name_2 ) ); |
---|
34 | } |
---|
35 | |
---|
36 | function test_removal() { |
---|
37 | // remove_settings_field( $this->option_name, $this->option_group, $this->settings_section ); |
---|
38 | // remove_settings_field( $this->option_name_2, $this->option_group, $this->settings_section ); |
---|
39 | // remove_settings_section( $this->settings_section, $this->options_page ); |
---|
40 | |
---|
41 | /* |
---|
42 | global $wp_settings_sections, $wp_settings_fields; |
---|
43 | ?> |
---|
44 | <pre><? var_dump($wp_settings_sections) ?></pre> |
---|
45 | <pre><? var_dump($wp_settings_fields) ?></pre> |
---|
46 | <? |
---|
47 | */ |
---|
48 | } |
---|
49 | |
---|
50 | function add_settings_page() { |
---|
51 | $this->options_page_handle = add_options_page( __( 'Dummy Plugin' ), __( 'Dummy Plugin' ), 'manage_options', $this->options_page, array( &$this, 'settings_page' ) ); |
---|
52 | } |
---|
53 | |
---|
54 | function settings_page() { |
---|
55 | ?> |
---|
56 | <div class="wrap"> |
---|
57 | <div id="icon-options-general" class="icon32"></div> |
---|
58 | <h2>Dummy Plugin</h2> |
---|
59 | <?php if ( current_user_can( 'manage_options' ) ): ?> |
---|
60 | <p>This is a test of the Settings API.</p> |
---|
61 | <form action="options.php" method="post"> |
---|
62 | <?php settings_fields( $this->option_group ) ?> |
---|
63 | <?php do_settings_sections( $this->options_page ) ?> |
---|
64 | <p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="Save Changes"></p> |
---|
65 | </form> |
---|
66 | <?php else: ?> |
---|
67 | <p><strong>You do not have permission to be here!</strong></p> |
---|
68 | <?php endif ?> |
---|
69 | </div> |
---|
70 | <?php |
---|
71 | } |
---|
72 | |
---|
73 | function settings_section_text( $section ) { |
---|
74 | switch ( $section['id'] ) { |
---|
75 | case $this->settings_section: |
---|
76 | echo '<p>Some would argue that this plugin is a waste of time.</p>'; |
---|
77 | break; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | function settings_field_input( $args = null ) { |
---|
82 | switch ( $args['type'] ) { |
---|
83 | case $this->option_name: |
---|
84 | $option = get_option( $this->option_name, 'Default Value' ); |
---|
85 | echo '<input id="' . $this->option_name . '" name="' . $this->option_name . '" type="text" value="' . esc_attr( $option ) . '" />'; |
---|
86 | break; |
---|
87 | case $this->option_name_2: |
---|
88 | $option = get_option( $this->option_name_2, 'Default Value' ); |
---|
89 | echo '<input id="' . $this->option_name_2 . '" name="' . $this->option_name_2 . '" type="text" value="' . esc_attr( $option ) . '" />'; |
---|
90 | break; |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | } |
---|
95 | |
---|
96 | if ( class_exists( 'DummyPlugin' ) ) |
---|
97 | $DummyPlugin = new DummyPlugin(); |
---|
98 | |
---|
99 | ?> |
---|