Administration pages can make any theme or plugin that has changeable settings more usable — and they’re relatively simple to add.

Because most plugins and themes don’t need their own top level menu, we’ll be using a function called bb_admin_add_submenu to tell bbPress that our page exists.

// ...

if ( BB_IS_ADMIN ) {
    bb_admin_add_submenu( __( 'FooBar', 'foobar' ),   'administrate', 'foobar_admin_page', 'options-general.php' );
}

function foobar_admin_page() { ?>
<h2><?php _e( 'FooBar', 'foobar' ); ?></h2>
<?php do_action( 'bb_admin_notices' ); ?>
<p><?php _e( 'It works!', 'foobar' ); ?></p>
<?php }

// ...

This code sets up a function to generate the administration page and tells bbPress that it exists. The page is under the general options page (the page you get to when you click “settings”), and can only be accessed by users with the “administrate” privilege. Other common privileges are “moderate” and “use_keys,” for moderators and key masters respectively.

From here, you can add HTML code to have a settings page. A good function to look at is bb_option_form_element. You can add an action handler to [function name]_pre_head to process the form before the page starts being rendered, so you can use redirects and other HTTP headers.

Advertisements