The Super Duper WordPress Settings class is intended to make it easy for me to add options pages and menus (as opposed to the WP way, which is incredibly and unnecessary difficult).
Put these files in your theme folder somewhere, then include the class include 'SDWPSettings.php';.
Then instantiate it, and add pages and menus:
( new SDWPSettings() )
->...
->...
.....
#Functions
Sets the current prefix to work with
Sets the position (or priority) in the menu where we will start inserting items.
Expects a URL.
Adds a separator, with optional ID.
Adds a page to the menu. If a menu was not defined by this time, a generic menu will be created
Adds a subpage under the current page.
Adds a node to the top admin bar.
Adds a new section to the current page or subpage. If no current page, one will be created.
Adds an option to the current section. If no section, one will be created. It takes an array as argument:
array(
'id' =>
'title' =>
'description' =>
'type' => checkbox | textarea | textarea_code
'default' =>
'syntax' => html | javascript | css (only if type == textarea_code)
)
This class recognizes certain keywords. As a consequence, it is possible to use:
->add_checkbox( $args );
->add_textarea( $args );
...
( new SDWPSettings() )
->set_prefix( 'my_wp_' )
->set_position( 70 )
->add_separator()
->add_menu_page( 'My Theme Options' )
->add_section( 'General Options' )
->add_option( array(
'id' => 'checkbox_1',
'title' => __( 'This is a checkbox', 'textdomain' )
'type' => 'checkbox'
'default' => 1
) )
->add_option( array(
'id' => 'textarea_1',
'title' => __( 'This is my textarea', 'textdomain' ),
'type' => 'textarea'
) )
->add_section( 'Advanced Options' )
->add_option( array(
'id' => 'textarea_code_1',
'title' => __( 'Enter code here', 'textdomain' ),
'description' => __( 'Here you can enter your Google Analytics code', 'textdomain' ),
'type' => 'textarea_code',
'syntax' => 'javascript'
) )
->add_submenu_page( 'This is a page under the previous one' )
->add_section(...)
..... and so on .....
; // don't forget the semocolon at the end