Skip to content

Instantly share code, notes, and snippets.

@cgrymala
Created June 24, 2014 15:19
Show Gist options
  • Save cgrymala/5457bc5309c4bb6c81a9 to your computer and use it in GitHub Desktop.
Save cgrymala/5457bc5309c4bb6c81a9 to your computer and use it in GitHub Desktop.
Registering a New Options Page in WordPress
<?php
if ( ! class_exists( 'Sample_Plugin' ) ) {
class Sample_Plugin {
var $text_domain = 'sample_plugin';
var $options_page_slug = 'sample-options-page'; /* Because you will use this in a lot of places, we'll define it here */
function __construct() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
function admin_menu() {
add_options_page(
/* $page_title = */__( 'Sample Options Page', $this->text_domain ), /* Will be used as <title> element on page, only */
/* $menu_title = */__( 'Sample Options', $this->text_domain ), /* Will appear as the name within the admin menu */
/* $capability = */'manage_options', /* Be sure to choose a capability that makes sense for your plugin */
/* $menu_slug = */$this->options_page_slug, /* Make this unique, so that no other plugin/theme will clash with it */
/* $callback = */array( $this, 'do_options_page' ) /* This will actually output the HTML for the options page */
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment