Skip to content

Instantly share code, notes, and snippets.

@dcangulo
Created April 3, 2018 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcangulo/70c9fb1c7570e5b6cd58d162bbaa5379 to your computer and use it in GitHub Desktop.
Save dcangulo/70c9fb1c7570e5b6cd58d162bbaa5379 to your computer and use it in GitHub Desktop.
A WordPress plugin settings page template. Visit https://www.davidangulo.xyz/ for more information.
<?php
/*
Plugin Name: Wordpress plugin with settings
Plugin URI: wordpress.org/plugins
Description: Just another WordPress plugin with settings page.
Version: 1.0.0
Author: David Angulo
Author URI: https://www.davidangulo.xyz/
License: GPL2
*/
add_action("admin_menu", "registerOptionPage");
function registerOptionPage() {
add_options_page("Plugin Name","Plugin Name","manage_options","myPluginSettings","optionPageContent");
}
function optionPageContent() {
?>
<h2>Plugin Name</h2>
<p>These are the settings for your plugin.</p>
<form method="post" action="options.php">
<?php
settings_fields("myPluginSettings");
?>
<table class="form-table">
<tbody>
<tr>
<th>Setting 1</th>
<td>
<input type="text" name="setting1" id="setting1" value="<?php echo get_option('setting1');?>"><br><span class="description"> Enter your description for the setting 1 here.</span>
</td>
</tr>
<tr>
<th>Setting 2</th>
<td>
<input type="text" name="setting2" id="setting2" value="<?php echo get_option('setting2');?>"><br><span class="description"> Enter your description for the setting 2 here.</span>
</td>
</tr>
</tbody>
</table>
<?php
submit_button();
?>
</form>
<?php
}
add_action("admin_init","registerPluginSettings");
function registerPluginSettings() {
register_setting("myPluginSettings","setting1");
register_setting("myPluginSettings","setting2");
}
//Visit the tutorial for more information
//https://www.davidangulo.xyz/website-development/how-to-create-a-settings-page-for-your-wordpress-plugin/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment