Skip to main content
null 💻 notes

WordPress Easy Options Page Wrapper

This is a wrapper of Tareq Hasan's WordPress Settings API class. It changes the way you use his class by using member functions to modify an instantiated class, rather than modifying the class itself.

You can download a full copy of the wrapper from GitHub here. The main file is class.eop.php, and there is an example file (surreptitiously named example.php) located there, too.

Here's what's in the example:

require_once dirname( __FILE__ ) . '/class.eop.php';

// Please take a look at the documentation/tutorial at
// http://lawsonry.com/simple-plugin-template

// Each options page is a separate EasyOptionsPage object, and each one
// gets one link in the Settings tab.
$settings = new EasyOptionsPage(
"Link in the settings tab", "Title of the options page");

// Each set of options are organized by "section." Each section is made available
// through a tab at the top of the screen.
// Declare all of the sections you want to use up front.
$settings->AddSection("First Tab");
$settings->AddSection("Another Tab");

// When you're ready to start editing a section, you "open it" by calling
// the EditSection member function of the EasyOptionsPage class.
$settings->EditSection("First Tab");

// Now that our section is "open" for editing, we'll add options. A complete
// list of options is available at http://lawsonry.com/simple-plugin-template

// Here's an example textarea.
$settings->AddOption(
	array(
       'name' => 'user_bio',
       'label' => __( 'Your biography', 'basic' ),
       'desc' => __( 'Description', 'basic' ),
       'type' => 'textarea'
   ));

// Here's an example multicheck
$settings->AddOption(
	array(
	    'name' => 'favorite_things',
	    'label' => __( 'What do you like *most* about Jesse?', 'basic' ),
	    'desc' => __( 'Here is where we learn a little too much about you.', 'basic' ),
	    'type' => 'multicheck',
	    'options' => array(
	        'one' => 'His sense of humor',
	        'two' => 'His uncanny ability to distract himself',
	        'three' => 'His unrivaled coffee consumption habits',
	        'four' => 'His penchant for pendants'
	    )
	    ));

// When we're ready to edit another section, simply call the member function
$settings->EditSection("Another Tab");

$settings->Register();

The above code will render a page that looks like this:

Screen Shot 2013-12-03 at 8.59.57 AM

This is a work in progress but mostly not kept up anymore. You're more than welcome to take it and do with it as you please. I'm working on a simplified way to extract and render the data but it's a very small side project of an even older side project.

The more robust and functional version of this is coming soon in a drag-and-drop plugin editor I'm working on. Stay tuned!