Advertisement
Guest User

NerdOfLinux: WordPress Error

a guest
Aug 14th, 2017
759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.46 KB | None | 0 0
  1.     class member_only {
  2.     /* Create blank array */
  3.     public function __construct() {
  4.         //$this = [];
  5.         // Hook into the admin menu
  6.         add_action( 'admin_menu', array( $this, 'settings_page' ) );
  7.         add_action( 'admin_init', array( $this, 'setup_sections' ) );
  8.         add_action( 'admin_init', array( $this, 'setup_fields' ) );
  9.     }
  10.     public function settings_page() {
  11.         //Create the menu item and page
  12.         $parent_slug = "member_only_fields";
  13.         $page_title = "Member Only Content Settings Page";
  14.         $menu_title = "Member Only Content";
  15.         $capability = "manage_options";
  16.         $slug = "member_only_fields";
  17.         $callback = array( $this, 'settings_page_content' );
  18.         add_submenu_page( "options-general.php", $page_title, $menu_title, $capability, $slug, $callback );
  19.     }
  20.     /* Create the page*/
  21.     public function settings_page_content() { ?>
  22.         <div class="wrap">
  23.             <h2> Member Only Content </h2>
  24.             <form method="post" action="options.php">
  25.                 <?php
  26.                     settings_fields("member_only_fields");
  27.                     do_settings_sections("member_only_fields");
  28.                     submit_button();
  29.                 ?>
  30.             </form>
  31.     <?php
  32.     }
  33.     /* Add options to settings page*/
  34.     public function setup_sections() {
  35.         add_settings_section("categories", "Member Only Categories: ", array($this, 'section_callback'), "member_only_fields");
  36.         add_settings_section("loginURL", "Login URL: ", array($this, 'section_callback'), "member_only_fields");
  37.     }
  38.     /* Setup section_callback */
  39.     public function section_callback( $arguments ) {
  40.         /* Set up input*/
  41.         switch( $arguments['id'] ){
  42.             case "categories" :
  43.                 echo "Categories that will trigger the member only message.";
  44.                 break;
  45.             case "loginURL":
  46.                 echo "The login URL of your site. ";
  47.             break;
  48.         }
  49.     }
  50.     public function setup_fields() {
  51.         add_settings_field( 'categories', 'Categories: ', array( $this, 'field_callback' ), 'member_only_fields', 'categories' );
  52.     }
  53.     /* Create input fields*/
  54.         public function field_callback ( $arguments ) {
  55.             echo "<input name=\"categories\" id=\"categories\" type=\"text\" value=\"" .get_option("categories"). "\"\>";
  56.             register_setting("member_only_fields", "categories");
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement