page_title = __( 'Depicter Settings', 'depicter' ); $this->menu_title = __( 'Settings', 'depicter' ); $this->capability = 'manage_depicter'; $this->menu_slug = 'depicter-settings'; // $this->form_action = 'admin.php?page=depicter-settings'; $this->form_action = 'options.php'; $this->option_group = 'depicter_'; add_action( 'admin_menu', array( $this, 'add_settings_page' ) ); add_action( 'admin_init', array( $this, 'add_settings' ) ); } /** * Adds a submenu page to the Settings main menu. */ public function add_settings_page() { /** * Params for add_options_page * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected. * @param string $menu_title The text to be used for the menu. * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $callback Optional. The function to be called to output the content for this page. * @param int $position Optional. The position in the menu order this item should appear. * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. */ // add_options_page( // $this->page_title, // $this->menu_title, // $this->capability, // $this->menu_slug, // array( $this, 'settings_page_html' ) // ); add_submenu_page( 'depicter-dashboard', $this->page_title, $this->menu_title, $this->capability, $this->menu_slug, [ $this, 'settings_page_html' ] ); } /** * Compose settings */ public function add_settings() { // Define Sections ----------------------------------------------------. /** * Adds a new section to a settings page. * * Part of the Settings API. Use this to define new settings sections for an admin page. * Show settings sections in your admin page callback function with do_settings_sections(). * Add settings fields to your section with add_settings_field(). * * The $callback argument should be the name of a function that echoes out any * content you want to show at the top of the settings section before the actual * fields. It can output nothing if you want. * * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags. * @param string $title Formatted title of the section. Shown as the heading for the section. * @param callable $callback Function that echos out any content at the top of the section (between heading and fields). * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include * 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using * add_options_page(); */ add_settings_section( 'depicter_general_section', __( 'General', 'depicter' ), null, $this->menu_slug ); add_settings_section( 'depicter_performance_section', __( 'Performance', 'depicter' ), null, $this->menu_slug ); // Input text field ---------------------------------------------------. /** * Adds a new field to a section of a settings page. * * Part of the Settings API. Use this to define a settings field that will show * as part of a settings section inside a settings page. The fields are shown using * do_settings_fields() in do_settings_sections(). * * The $callback argument should be the name of a function that echoes out the * HTML input tags for this setting field. Use get_option() to retrieve existing * values to show. * * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags. * @param string $title Formatted title of the field. Shown as the label for the field * during output. * @param callable $callback Function that fills the field with the desired form inputs. The * function should echo its output. * @param string $page The slug-name of the settings page on which to show the section * (general, reading, writing, ...). * @param string $section Optional. The slug-name of the section of the settings page * in which to show the box. Default 'default'. * @param array $args { * Optional. Extra arguments used when outputting the field. * * @type string $label_for When supplied, the setting title will be wrapped * in a `