mirror of
https://github.com/inretio/WordPress-Plugin-Boilerplate
synced 2025-01-31 15:05:33 +02:00
Merge pull request #27 from mikkelbreum/master
improvements and additions (added settings page)
This commit is contained in:
commit
11af5e0d11
3 changed files with 74 additions and 9 deletions
|
@ -41,8 +41,15 @@ class PluginName {
|
|||
// Load plugin text domain
|
||||
add_action( 'init', array( $this, 'plugin_textdomain' ) );
|
||||
|
||||
// Add the options page and menu item
|
||||
// Uncomment the following line to enable the Settings Page for the plugin
|
||||
# add_action('admin_menu', array( $this, 'plugin_admin_menu' ) );
|
||||
|
||||
// Register admin styles and scripts
|
||||
add_action( 'admin_print_styles', array( $this, 'register_admin_styles' ) );
|
||||
// If the Settings page has been activated (above), the scripts and styles
|
||||
// will only be loaded on the settings page. If not, they will be loaded for all
|
||||
// admin pages.
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_styles' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_scripts' ) );
|
||||
|
||||
// Register site styles and scripts
|
||||
|
@ -105,18 +112,53 @@ class PluginName {
|
|||
*/
|
||||
public function register_admin_styles() {
|
||||
|
||||
// TODO: Change 'plugin-name' to the name of your plugin
|
||||
wp_enqueue_style( 'plugin-name-admin-styles', plugins_url( 'plugin-name/css/admin.css' ) );
|
||||
/*
|
||||
* Check if the plugin has registered a settings page
|
||||
* and if it has, make sure only to enqueue the scripts on the relevant screens
|
||||
*/
|
||||
|
||||
if ( isset($this->plugin_screen_slug) ){
|
||||
|
||||
/*
|
||||
* Check if current screen is the admin page for this plugin
|
||||
* Don't enqueue script/style if it's not
|
||||
*/
|
||||
|
||||
$screen = get_current_screen();
|
||||
if ( $screen->id != $this->plugin_screen_slug )
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'plugin-name-admin-styles', plugins_url( 'css/admin.css', __FILE__ ) );
|
||||
|
||||
} // end register_admin_styles
|
||||
|
||||
|
||||
/**
|
||||
* Registers and enqueues admin-specific JavaScript.
|
||||
*/
|
||||
public function register_admin_scripts() {
|
||||
|
||||
// TODO: Change 'plugin-name' to the name of your plugin
|
||||
wp_enqueue_script( 'plugin-name-admin-script', plugins_url( 'plugin-name/js/admin.js' ), array('jquery') );
|
||||
/*
|
||||
* Check if the plugin has registered a settings page
|
||||
* and if it has, make sure only to enqueue the scripts on the relevant screens
|
||||
*/
|
||||
|
||||
if ( isset($this->plugin_screen_slug) ){
|
||||
|
||||
/*
|
||||
* Check if current screen is the admin page for this plugin
|
||||
* Don't enqueue script/style if it's not
|
||||
*/
|
||||
|
||||
$screen = get_current_screen();
|
||||
if ( $screen->id != $this->plugin_screen_slug )
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
wp_enqueue_script( 'plugin-name-admin-script', plugins_url( 'js/admin.js', __FILE__ ), array('jquery') );
|
||||
|
||||
} // end register_admin_scripts
|
||||
|
||||
|
@ -125,8 +167,7 @@ class PluginName {
|
|||
*/
|
||||
public function register_plugin_styles() {
|
||||
|
||||
// TODO: Change 'plugin-name' to the name of your plugin
|
||||
wp_enqueue_style( 'plugin-name-plugin-styles', plugins_url( 'plugin-name/css/display.css' ) );
|
||||
wp_enqueue_style( 'plugin-name-plugin-styles', plugins_url( 'css/display.css', __FILE__ ) );
|
||||
|
||||
} // end register_plugin_styles
|
||||
|
||||
|
@ -135,11 +176,31 @@ class PluginName {
|
|||
*/
|
||||
public function register_plugin_scripts() {
|
||||
|
||||
// TODO: Change 'plugin-name' to the name of your plugin
|
||||
wp_enqueue_script( 'plugin-name-plugin-script', plugins_url( 'plugin-name/js/display.js' ), array('jquery') );
|
||||
wp_enqueue_script( 'plugin-name-plugin-script', plugins_url( 'js/display.js', __FILE__ ), array('jquery') );
|
||||
|
||||
} // end register_plugin_scripts
|
||||
|
||||
|
||||
function plugin_admin_menu() {
|
||||
// TODO: Change 'Page Title' to the title of your plugin admin page
|
||||
// TODO: Change 'Menu Text' to the text for menu item for the plugin settings page
|
||||
// TODO: Change 'plugin-name' to the name of your plugin
|
||||
$this->plugin_screen_slug = add_plugins_page('Page Title', 'Menu Text', 'read', 'plugin-name', array( $this, 'plugin_admin_page' ));
|
||||
|
||||
} // end plugin_admin_menu
|
||||
|
||||
|
||||
function plugin_admin_page() {
|
||||
|
||||
// output the cpanel
|
||||
include_once('views/admin_open.php');
|
||||
include_once('views/admin.php'); // outputs the settings/form markup for the plugin admin markup
|
||||
include_once('views/admin_close.php');
|
||||
|
||||
} // end plugin_admin_page
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------*
|
||||
* Core Functions
|
||||
*---------------------------------------------*/
|
||||
|
|
1
plugin-boilerplate/views/admin_close.php
Normal file
1
plugin-boilerplate/views/admin_close.php
Normal file
|
@ -0,0 +1 @@
|
|||
</div><!-- .wrap -->
|
3
plugin-boilerplate/views/admin_open.php
Normal file
3
plugin-boilerplate/views/admin_open.php
Normal file
|
@ -0,0 +1,3 @@
|
|||
<div class="wrap">
|
||||
<?php screen_icon(); ?>
|
||||
<h2>My Plugin Name</h2>
|
Loading…
Add table
Reference in a new issue