Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This shows you to setup a page for a WordPress plugin with settings including a select field
<?php
function pegasus_nav_plugin_settings_page() { ?>
<div class="wrap">
<h1>Nav</h1>
<form method="post" action="options.php">
<?php
settings_fields("section2");
do_settings_sections("theme-options2");
?>
<ol>
<li>None - This will keep the toggle button active at all times. It's like having the mobile menu for all screen sizes.</li>
<li>Navbar Expand - This is used if you want the dekstop view of the naviagtion to stay even on mobile.</li>
<li>Navbar Small - This will make the menu change to toggle at 575px (Mobile). </li>
<li>Navbar Medium - This will make the menu change to toggle at 767px (Mobile). </li>
<li>Navbar Large - This will make the menu change to toggle at 991px (Mobile). </li>
<li>Navbar X-Large - This will make the menu change to toggle at 1199px (Mobile). </li>
</ol>
<?php
submit_button();
?>
</form>
</div>
<?php
}
function pegasus_nav_plugin_shortcode_settings_page() { ?>
<div class="wrap pegasus-wrap">
<h1>Shortcode Usage</h1>
<p>Menu Usage: <pre>[menu menu="primary"]</pre></p>
<p>Bootstrap Menu Usage: <pre>[bootstrap_menu menu="primary" additional_classes="test"]</pre></p>
<p>Bootstrap Menu Usage: <pre>[bootstrap_menu menu="primary" additional_classes="navbar-expand"]</pre></p>
<p style="color:red;">MAKE SURE YOU DO NOT HAVE ANY RETURNS OR <?php echo htmlspecialchars('<br>'); ?>'s IN YOUR SHORTCODES, OTHERWISE IT WILL NOT WORK CORRECTLY</p>
</div>
<?php
}
function pegasus_select_bootstrap_style_option() { ?>
<select id="select_for_bootstrap_class" name="select_for_bootstrap_class">
<option value="none" <?php selected( get_option('select_for_bootstrap_class'), 'none', 'selected="selected"' ); ?>><?php echo esc_attr( __( 'None' ) ); ?></option>
<option value="navbar-expand" <?php selected( get_option('select_for_bootstrap_class'), 'navbar-expand', 'selected="selected"' ); ?>><?php echo esc_attr( __( 'Navbar Expand' ) ); ?></option>
<option value="navbar-expand-sm" <?php selected( get_option('select_for_bootstrap_class'), 'navbar-expand-sm', 'selected="selected"' ); ?>><?php echo esc_attr( __( 'Expand Small' ) ); ?></option>
<option value="navbar-expand-md" <?php selected( get_option('select_for_bootstrap_class'), 'navbar-expand-md', 'selected="selected"' ); ?>><?php echo esc_attr( __( 'Expand Medium' ) ); ?></option>
<option value="navbar-expand-lg" <?php selected( get_option('select_for_bootstrap_class'), 'navbar-expand-lg', 'selected="selected"' ); ?>><?php echo esc_attr( __( 'Expand Large' ) ); ?></option>
<option value="navbar-expand-xl" <?php selected( get_option('select_for_bootstrap_class'), 'navbar-expand-xl', 'selected="selected"' ); ?>><?php echo esc_attr( __( 'Expand X-Large' ) ); ?></option>
</select>
<label for="select_for_bootstrap_class"><br/>This will be the style for all the Bootstrap nav menu's generated with a shortcode. <br/>You can override it by adding the correct class to the additional_classes parameter.</label>
<p>Example: <pre>[bootstrap_menu menu="primary" additional_classes=" navbar-expand-md test-class"]</pre></p>
<?php
}
function display_nav_plugin_panel_fields() {
add_settings_section("section2", "Shortcode Settings", null, "theme-options2");
add_settings_field("select_for_bootstrap_class", "Global Bootstrap Nav Type", "pegasus_select_bootstrap_style_option", "theme-options2", "section2");
//================
//REGISTER SETTINGS
//=================
//register_setting("section", "chk_slider_cpt");
register_setting("section2", "select_for_bootstrap_class");
}
add_action("admin_init", "display_nav_plugin_panel_fields");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment