Settings Page API

WP e-Commerce Settings Page API.

Third-party plugin / theme developers can add their own tabs to WPEC store settings page.

Let’s say you want to create a tab for your plugin called “Recommendation System”, for example. You first need to register the tab ID and title like this:

[php]

function my_plugin_settings_tabs( $settings_page ) {

$settings_page->register_tab( ‘recommendation_system’, ‘Recommendation System’ );

}

add_action( ‘wpsc_load_settings_tab_class’, ‘my_plugin_settings_tabs’, 10, 1 );

[/php]

Note that you need to hook into wpsc_load_settings_tab_class to do this.

The next step is to create a class for your tab which inherits from the base WPSC_Settings_Tab. The name of the class needs to follow this convention: all the words have to be capitalized and separated with an underscore, and prefixed with WPSC_Settings_Tab_.

In our example, because we registered our tab ID as recommendation_system, the class name should be WPSC_Settings_Tab_Recommendation_System.

[php]

class WPSC_Settings_Tab_Recommendation_System extends WPSC_Settings_Tab

{

public function display() {

echo ‘<h3>Recommendation System Settings</h3>’;

// output your tab content here

}

}

[/php]

All tab has to implement a method display() which outputs the HTML content for the tab. You don’t need to output the <form> element because it will be done for you.

When outputting your form fields for the tab, name the fields wpsc_options[$your_option_name] so that they will automatically get saved to the database when the user submits the form. E.g.:

[php]

<input type="text" value="something" name="wpsc_options[some_option]" />

[/php]

If you need to handle the form submission yourself, create a method in your tab class called callback_submit_options(). Then process your submitted fields there.

[php]

class WPSC_Settings_Tab_Recommendation_System extends WPSC_Settings_Tab

{

// …

public function callback_submit_options() {

if ( isset( $_POST[‘my_option’] ) )

update_option( ‘my_option’, $_POST[‘my_option’] );

}

// …

}

[/php]