-
Notifications
You must be signed in to change notification settings - Fork 5
/
client-dash-extension-boilerplate.php
234 lines (200 loc) · 6.83 KB
/
client-dash-extension-boilerplate.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
/*
Plugin Name: Client Dash Extension Boilerplate
Description: Starting point for making an add-on for Client Dash.
Version: 0.2.1
Author: Kyle Maurer
Author URI: http://realbigmarketing.com/staff/kyle
*/
// FIXME Style not loading
// Change me! Change me to the function just below
if ( ! function_exists( 'cd_boilerplate' ) ) {
/**
* The function to launch our plugin.
*
* This entire class is wrapped in this function because we have to ensure that Client Dash has been loaded before our
* extension.
*
* NOTE: This function needs to be changed to whatever your extension is. Also change it at the bottom under
* "add_action( 'plugins_loaded', cd_boilerplate' )". ALSO change just above "function_exists()".
*
* ALSO NOTE: You also need to change the function name "_cd_boilerplate_notice" to something else. Both way at the
* bottom, and also right here, under "add_action( 'admin_notices'..."
*
* Please and thank you.
*/
function cd_boilerplate() {
if ( ! class_exists( 'ClientDash' ) ) {
// Change me! Change me to the name of the notice function at the bottom
add_action( 'admin_notices', '_cd_boilerplate_notice' );
return;
}
/**
* Class MyCDExtension
*
* The main class for the extension. Be sure to rename this class something that is unique to your extension.
* Duplicate classes will break PHP.
*/
class MyCDExtension extends ClientDash {
/**
* Your unique ID.
*
* This will be prefixed on many things throughout the plugin. So make it relatable to the plugin, but also
* unique so it will not be used by ANYTHING else. As an example, Client Dash's prefix is "cd".
*
* Feel free to modify this example.
*/
public static $ID = 'boilerplate';
/**
* This is the page that you want your new tab to reside in. This page must be one of the four core Client Dash
* pages: Account, Reports, Help, or Webmaster.
*
* Feel free to modify this example.
*/
private static $page = 'Account';
/**
* Your tab name.
*
* This is the name of the tab that your plugin's content section will reside in. You may set this to an
* existing tab name if you wish, in which case your plugin's content will appear in a new content section in
* the tab.
*
* Feel free to modify this example.
*/
private static $tab = 'Boilerplate';
/**
* This is the settings tab name.
*
* All of your plugin settings will reside here. This may also be the name of an existing tab.
*
* Feel free to modify this example.
*/
public static $settings_tab = 'Boilerplate';
/**
* This is the section name of your boilerplate.
*
* This will be the display name of the content section that this plugin's content resides in. If there is only
* one content section within the tab, the name will not show.
*
* Feel free to modify this example.
*/
private static $section_name = 'Boilerplate Content';
/**
* This is the current version of your plugin. Keep it up to do date!
*/
public static $extension_version = '0.1.3';
/**
* This is the path to the plugin.
*
* Private.
*
* Don't worry about messing with this property.
*/
public $_path;
/**
* This is the url to the plugin.
*
* Private.
*
* Don't worry about messing with this property.
*/
public $_url;
/**
* This constructor function sets up what happens when the plugin is activated. It is where you'll place all your
* actions, filters and other setup components.
*
* Don't worry about messing with this function.
*/
public function __construct() {
// Register our styles
add_action( 'admin_init', array( $this, 'register_styles' ) );
// Add our styles conditionally
add_action( 'admin_enqueue_scripts', array( $this, 'add_styles' ) );
// Add our new content section
$this->add_content_section(
array(
'name' => self::$section_name,
'tab' => self::$tab,
'page' => self::$page,
'callback' => array( $this, 'section_output' )
)
);
// Set the plugin path
$this->_path = plugin_dir_path( __FILE__ );
// Set the plugin url
$this->_url = plugins_url( '', __FILE__ );
}
/**
* Register our styles.
*
* Feel free to modify or add to this example.
*/
public function register_styles() {
wp_register_style(
self::$ID . '-style',
$this->_url . 'style.css',
null,
self::$extension_version
);
}
/**
* Add our styles.
*
* If you want the styles to show up on the entire back-end, simply remove all but:
* wp_enqueue_style( "$this->$ID-style" );
*
* Feel free to modify or add to this example.
*/
public function add_styles() {
$page_ID = self::translate_name_to_id( self::$page );
$tab_ID = self::translate_name_to_id( self::$tab );
$settings_tab_ID = self::translate_name_to_id( self::$settings_tab );
// Only add style if on extension tab or on extension settings tab
if ( self::is_cd_page( $page_ID, $tab_ID ) || self::is_cd_page( 'cd_settings', $settings_tab_ID ) ) {
wp_enqueue_style( self::$ID . '-style' );
}
}
/**
* Our section output.
*
* This is where all of the content section content goes! Add anything you like to this function.
*
* Feel free to modify or add to this example.
*/
public function section_output() {
// CHANGE THIS
echo 'This is where your new content section\'s content goes.';
}
}
// Instantiate the class
$MyCDExtension = new MyCDExtension();
// Include the file for your plugin settings. Simply remove or comment this line to disable the settings
// Remove if you don't want settings
include_once( "{$MyCDExtension->_path}inc/settings.php" );
// Include the file for your plugin widget. Simply remove or comment this line to disable the widget
// Remove if you don't want widgets
include_once( "{$MyCDExtension->_path}inc/widgets.php" );
// Include the file for your plugin menus. Simply remove or comment this line to disable the widget
// Remove if you don't want menus
include_once( "{$MyCDExtension->_path}inc/menus.php" );
}
// Change me! Change me to the name of the function at the top.
add_action( 'plugins_loaded', 'cd_boilerplate' );
}
if ( ! function_exists( '_cd_boilerplate_notice' ) ) {
/**
* Notices for if CD is not active.
*
* Change me! Change my name to something unique (and also change the add_action at the top of the file). And change
* the name in function_exists().
*/
function _cd_boilerplate_notice() {
?>
<div class="error">
<p>You have activated a plugin that requires <a href="http://w.org/plugins/client-dash">Client Dash</a>
version 1.6 or greater.
Please install and activate <strong>Client Dash</strong> to continue using.</p>
</div>
<?php
}
}