wordpress menu template - add options menu

PHOTO EMBED

Mon Aug 29 2022 12:01:09 GMT+0000 (Coordinated Universal Time)

Saved by @khalidlogi #php

<?php

//create menu link

//Resgiter Settings
//fill in the settings menu

function mf_menu_create_link()
{

    /*

    add_submenu_page(
    string   $parent_slug,
    string   $page_title,
    string   $menu_title,
    string   $capability,
    string   $menu_slug,
    callable $function = ''
    );

     */

    add_options_page(
        'Facebook Footer Link',
        'Facebook Footer Link',
        'manage_options',
        'mf_optioins',
        'mf_options_content'
    );

}
function mf_options_content()
{

    //init global myf_options
    global $myf_options; //declare global myf_options in main class //Global Options Variables
    //$myf_options = get_option('myf_settings');

    ob_start(); ?>
<div class="wrap">
    <h2><?php _e('Facebook Footer Link Settings' . 'mf_domain'); ?></h2>

    <p><?php _e('Facebook Footer Link plugin ', 'mf_domain'); ?></p>

    <!-- set the action attribute to ""options.php-->
    <form method="post" action="options.php">

        <!--  // Output the hidden fields, nonce, etc. -->
        <?php settings_fields('myf_settings_group'); ?>
        <table class="form-table">
            <tbody>
                <tr>
                    <th scope="row"><label for="myf_settings[enable]">
                            <?php _e('enable', 'mf_domain'); ?>
                        </label>
                    </th>
                    <td><input type="checkbox" name="myf_settings[enable]" id="myf_settings[enable]" value="1"
                            <?php checked('1', $myf_options['enable']); ?>></td>
                </tr>

                <tr>
                    <th scope="row"><label for="myf_settings[facebook_url]">
                            <?php _e('Facebook url', 'mf_domain'); ?>
                        </label>
                    </th>
                    <td><input type="text" class="regular-text" name="myf_settings[facebook_url]"
                            id="myf_settings[facebook_url]" value="<?php echo $myf_options['facebook_url']; ?>">
                        <p class="description"> <?php _e('Enter your facebook url', 'mf_domain'); ?></p>
                    </td>
                </tr>

                <tr>
                    <th scope="row"><label for="myf_settings[link_color]">
                            <?php _e('Facebook url', 'mf_domain'); ?>
                        </label>
                    </th>
                    <td><input type="text" class="regular-text" name="myf_settings[link_color]"
                            id="myf_settings[link_color]" value="<?php echo $myf_options['link_color']; ?>">
                        <p class="description"> <?php _e('Enter your facebook link_color', 'mf_domain'); ?></p>
                    </td>
                </tr>

                <tr>
                    <th scope="row"><label for="myf_settings[enable]">
                            <?php _e('show_in_feed', 'mf_domain'); ?>
                        </label>
                    </th>
                    <td><input type="checkbox" name="myf_settings[show_in_feed]" id="myf_settings[show_in_feed]"
                            value="1" <?php checked('1', $myf_options['show_in_feed']); ?>></td>
                </tr>

            </tbody>
        </table>

        <p class="submit"><input name="submit" class="button button-primary" type="submit"
                value="<?php _e('save changes'); ?>" </p>
    </form>

</div>
<?php echo ob_get_clean();

}

function mf_register_settings()
{
    register_setting('myf_settings_group', 'myf_settings');
}

add_action('admin_init', 'mf_register_settings');
add_action('admin_menu', 'mf_menu_create_link');
content_copyCOPY