• tomwpumford

    (@tomwpumford)


    Below is a simple functions page which displays two custom wordpress dashboard menus. One main menu and a submenu.

    As you can see both pages (main and sub) have an input, one for name and one for email.

    Question as follows 1. Is there a way to simplify so i dont have to register 2 settings, 1 for each page? 2. What is the best way to show this frontend on the theme.

    <?php
    
    /* Add Page */
    
    add_action('admin_menu', 'settings' );
    add_action('admin_init', 'register_settings_page');
    add_action('admin_init', 'register_settings_sub_page');
    
    /* Add to WP admin menu */
    
    function settings() {
    add_menu_page( 'Settings Page', 'Settings Page', 'manage_options', 'settings-   page', 'settings_page');
    add_submenu_page( 'settings-page', 'Settings Page Sub', 'Settings Page Sub', 'manage_options', 'settings-page-sub', 'settings_page_sub');
    
    /* Register Settings */
    
    function register_settings_page() {
    register_setting('settings-page-reg', 'settings_name');
    }
    
    function register_settings_sub_page() {
    register_setting('settings-sub-page-reg', 'settings_email');
    }
    
    /*Add Content for Pages */
    
    function settings_page() {
    ?>
    <form method="post" action="options.php">
    <?php settings_fields('settings-page-reg'); ?>
    <label>Settings Page Input</label>
    <input name="settings_name" type="test" value="<?php echo get_option('settings_name'); ?>" />
    <input type="submit" value="<?php _e('Save') ?>" />
    </form>
    <?php
    }
    
    function settings_page_sub() {
    ?>
    <form method="post" action="options.php">
    <?php settings_fields('settings-sub-page-reg'); ?>
    <label>Settings Sub Page Input</label>
    <input name="settings_email" type="test" value="<?php echo get_option('settings_email'); ?>" />
    <input type="submit" value="<?php _e('Save') ?>" />
    </form>
    <?php
    }
    }
    ?>
    
    <html>
    <body>
    <h1>I want name here</h1>
    <p>I want email here</p>
    </body>
    <html>
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You don’t have to use the Settings API. But if you do not, you are responsible for handling your own form submits, and formatting the output to match the rest of the admin screens gets trickier. The advantage of not using it is you can then call the same display functions from the front end.

Viewing 1 replies (of 1 total)
  • The topic ‘Functions Custom Admin Page’ is closed to new replies.