-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-uconn-banner-admin.php
executable file
·208 lines (175 loc) · 5.13 KB
/
class-uconn-banner-admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
/**
* UConn Banner.
*
* @package UConn_Banner
* @author Joseph Thibeault <[email protected]>
* @license GPL-2.0+
* @link http://uconn.edu
* @copyright 2013 University of Connecticut
*/
/**
* Plugin class. This class should ideally be used to work with the
* administrative side of the WordPress site.
*
* If you're interested in introducing public-facing
* functionality, then refer to `class-uconn-banner.php`
*
* TODO: Rename this class to a proper name for your plugin.
*
* @package UConn_Banner_Admin
* @author Joseph Thibeault <[email protected]>
*/
class UConn_Banner_Admin {
/**
* Instance of this class.
*
* @since 1.0.0
*
* @var object
*/
protected static $instance = null;
/**
* Slug of the plugin screen.
*
* @since 1.0.0
*
* @var string
*/
protected $plugin_screen_hook_suffix = null;
/**
* Initialize the plugin by loading admin scripts & styles and adding a
* settings page and menu.
*
* @since 1.0.0
*/
private function __construct() {
/*
* Call $plugin_slug from public plugin class.
*
*/
$plugin = UConn_Banner::get_instance();
$this->plugin_slug = $plugin->get_plugin_slug();
// Add the options page and menu item.
add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) );
//add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
// Add an action link pointing to the options page.
$plugin_basename = plugin_basename( plugin_dir_path( __FILE__ ) . $this->plugin_slug . '.php' );
add_filter( 'plugin_action_links_' . $plugin_basename, array( $this, 'add_action_links' ) );
add_action( 'admin_init', array( $this, 'register_settings' ) );
}
/**
* Register the plugin's settings with the Wordpress core
*
* @since 1.0.0
*
* @return void No return value.
*/
public function register_settings() {
register_setting( 'uconnbanner-group', 'uconnbanner_options', array( $this, 'uconnbanner_options_validate') );
}
/**
* Validate the options inputs.
*
* @since 1.0.0
*
* @return array An array of validated options.
*/
public function uconnbanner_options_validate($input) {
$input['display_page_header'] = ($input['display_page_header'] == 1) ? true : false;
$input['department_title'] = ($input['department_title'] == "") ? "" : $input['department_title'];
$input['department_url'] = ($input['department_url'] == "") ? "" : $input['department_url'];
return $input;
}
/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Register and enqueue admin-specific style sheet.
*
* @since 1.0.0
*
* @return null Return early if no settings page is registered.
*/
public function enqueue_admin_styles() {
if ( ! isset( $this->plugin_screen_hook_suffix ) ) {
return;
}
$screen = get_current_screen();
if ( $this->plugin_screen_hook_suffix == $screen->id ) {
wp_enqueue_style( $this->plugin_slug .'-admin-styles', plugins_url( 'css/admin.css', __FILE__ ), array(), UConn_Banner::VERSION );
}
}
/**
* Register and enqueue admin-specific JavaScript.
*
* @since 1.0.0
*
* @return null Return early if no settings page is registered.
*/
public function enqueue_admin_scripts() {
if ( ! isset( $this->plugin_screen_hook_suffix ) ) {
return;
}
$screen = get_current_screen();
if ( $this->plugin_screen_hook_suffix == $screen->id ) {
wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ), UConn_Banner::VERSION );
}
}
/**
* Register the administration menu for this plugin into the WordPress Dashboard menu.
*
* @since 1.0.0
*/
public function add_plugin_admin_menu() {
/*
* Add a settings page for this plugin to the Settings menu.
*
* NOTE: Alternative menu locations are available via WordPress administration menu functions.
*
* Administration Menus: http://codex.wordpress.org/Administration_Menus
*
* For reference: http://codex.wordpress.org/Roles_and_Capabilities
*/
$this->plugin_screen_hook_suffix = add_options_page(
__( 'UConn Banner Settings', $this->plugin_slug ),
__( 'UConn Banner', $this->plugin_slug ),
'manage_options',
$this->plugin_slug,
array( $this, 'display_plugin_admin_page' )
);
}
/**
* Render the settings page for this plugin.
*
* @since 1.0.0
*/
public function display_plugin_admin_page() {
include_once( 'views/admin.php' );
}
/**
* Add settings action link to the plugins page.
*
* @since 1.0.0
*/
public function add_action_links( $links ) {
return array_merge(
array(
'settings' => '<a href="' . admin_url( 'options-general.php?page=' . $this->plugin_slug ) . '">' . __( 'Settings', $this->plugin_slug ) . '</a>'
),
$links
);
}
}