Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class member_only {
- /* Create blank array */
- public function __construct() {
- //$this = [];
- // Hook into the admin menu
- add_action( 'admin_menu', array( $this, 'settings_page' ) );
- add_action( 'admin_init', array( $this, 'setup_sections' ) );
- add_action( 'admin_init', array( $this, 'setup_fields' ) );
- }
- public function settings_page() {
- //Create the menu item and page
- $parent_slug = "member_only_fields";
- $page_title = "Member Only Content Settings Page";
- $menu_title = "Member Only Content";
- $capability = "manage_options";
- $slug = "member_only_fields";
- $callback = array( $this, 'settings_page_content' );
- add_submenu_page( "options-general.php", $page_title, $menu_title, $capability, $slug, $callback );
- }
- /* Create the page*/
- public function settings_page_content() { ?>
- <div class="wrap">
- <h2> Member Only Content </h2>
- <form method="post" action="options.php">
- <?php
- settings_fields("member_only_fields");
- do_settings_sections("member_only_fields");
- submit_button();
- ?>
- </form>
- <?php
- }
- /* Add options to settings page*/
- public function setup_sections() {
- add_settings_section("categories", "Member Only Categories: ", array($this, 'section_callback'), "member_only_fields");
- add_settings_section("loginURL", "Login URL: ", array($this, 'section_callback'), "member_only_fields");
- }
- /* Setup section_callback */
- public function section_callback( $arguments ) {
- /* Set up input*/
- switch( $arguments['id'] ){
- case "categories" :
- echo "Categories that will trigger the member only message.";
- break;
- case "loginURL":
- echo "The login URL of your site. ";
- break;
- }
- }
- public function setup_fields() {
- add_settings_field( 'categories', 'Categories: ', array( $this, 'field_callback' ), 'member_only_fields', 'categories' );
- }
- /* Create input fields*/
- public function field_callback ( $arguments ) {
- echo "<input name=\"categories\" id=\"categories\" type=\"text\" value=\"" .get_option("categories"). "\"\>";
- register_setting("member_only_fields", "categories");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement