Skip to content

Commit 1551adb

Browse files
committed
Editor config + Autoload docs
1 parent 1297c1e commit 1551adb

File tree

4 files changed

+191
-116
lines changed

4 files changed

+191
-116
lines changed

.editorconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# WordPress Coding Standards
5+
# https://make.wordpress.org/core/handbook/coding-standards/
6+
7+
root = true
8+
9+
[*]
10+
charset = utf-8
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
indent_style = tab
15+
indent_size = 4
16+
17+
[{.jshintrc,*.json,*.yml}]
18+
indent_style = space
19+
indent_size = 2
20+
21+
[{*.txt,wp-config-sample.php}]
22+
end_of_line = crlf

autoload.php

Lines changed: 128 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,51 @@
11
<?php
22
if ( ! defined( 'ABSPATH' ) ) exit;
33

4-
//Main plugin object to define the plugin
4+
/**
5+
* Main plugin object to define the plugin
6+
*/
57
if ( ! class_exists( 'PLUGIN_BUILD' ) ) {
68

79
final class PLUGIN_BUILD {
810

911

12+
protected static $text_domain = 'textdomain';
13+
protected static $php_ver_allowed = '5.4';
14+
protected static $plugin_table = 'plugin_db_table_name';
1015

16+
17+
/**
18+
* Install plugin setup
19+
*
20+
* @return Void
21+
*/
1122
public function installation() {
1223

13-
/**
14-
*
15-
* Plugin installation
16-
*
1724
if (class_exists('PLUGIN_INSTALL')) {
1825

1926
$install = new PLUGIN_INSTALL();
20-
$install->textDomin = 'textdomain';
21-
$install->phpVerAllowed = '';
22-
$install->pluginPageLinks = array(
27+
$install->text_domain = self::$text_domain;
28+
$install->php_ver_allowed = self::$php_ver_allowed;
29+
$install->plugin_page_links = array(
2330
array(
2431
'slug' => '',
2532
'label' => ''
2633
),
2734
);
2835
$install->execute();
2936
}
30-
*
31-
*/
3237
}
3338

3439

35-
36-
//Custom corn class, register it while activation
40+
/**
41+
* Custom corn class, register it while activation
42+
*
43+
* @return Void
44+
*/
3745
public function cron_activation() {
3846

3947
if ( class_exists( 'PLUGIN_CRON' ) ) {
48+
4049
$cron = new PLUGIN_CRON();
4150
$schedule = $cron->schedule_task(
4251
array(
@@ -51,47 +60,41 @@ public function cron_activation() {
5160
}
5261

5362

63+
/**
64+
* Install plugin data
65+
*
66+
* @return Void
67+
*/
5468
public function db_install() {
5569

56-
/**
57-
*
58-
* Install database by defining your SQL
59-
*
6070
if ( class_exists( 'PLUGIN_DB' ) ) {
71+
6172
$db = new PLUGIN_DB();
62-
$db->table = 'plugin_db_table_name';
73+
$db->table = self::$plugin_table;
6374
$db->sql = "ID mediumint(9) NOT NULL AUTO_INCREMENT,
6475
date date NOT NULL,
6576
UNIQUE KEY ID (ID)";
6677
$db->build();
6778
}
68-
*
69-
*
70-
* Optionally check if the DB table is installed correctly
71-
*
72-
if (get_option('_plugin_db_exist') == '0') {
79+
80+
if (get_option( '_plugin_db_exist') == '0' ) {
7381
add_action( 'admin_notices', array( $this, 'db_error_msg' ) );
7482
}
75-
*
76-
*/
7783

78-
/**
79-
*
80-
* Install DB options
81-
*
8284
$options = array(
83-
array( 'option_name', '__value__' ),
84-
);
85-
foreach ($options as $value) {
85+
array( 'option_name', '__value__' ),
86+
);
87+
foreach ( $options as $value ) {
8688
update_option( $value[0], $value[1] );
8789
}
88-
*
89-
*/
9090
}
9191

9292

93-
94-
//Notice of DB
93+
/**
94+
* Notice of DB
95+
*
96+
* @return string
97+
*/
9598
public function db_error_msg() { ?>
9699

97100
<div class="notice notice-error is-dismissible">
@@ -101,132 +104,170 @@ public function db_error_msg() { ?>
101104
}
102105

103106

104-
107+
/**
108+
* Uninstall plugin data
109+
*
110+
* @return Void
111+
*/
105112
public function db_uninstall() {
106113

107-
/**
108-
*
109-
* Important table name declarition
110-
*
111-
$tableName = 'plugin_db_table_name';
114+
$table_name = self::$plugin_table;
112115

113116
global $wpdb;
114-
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}$tableName" );
117+
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}$table_name" );
118+
115119
$options = array(
116-
'_plugin_db_exist'
117-
);
118-
foreach ($options as $value) {
119-
delete_option($value);
120+
'_plugin_db_exist'
121+
);
122+
foreach ( $options as $value ) {
123+
delete_option( $value );
120124
}
121-
*
122-
*/
123125
}
124126

125127

128+
/**
129+
* CRON callback
130+
*
131+
* @return Void
132+
*/
126133
public function do_cron_job_function() {
127134

128135
//Do cron function
129136
}
130137

131138

139+
/**
140+
* Run CRON action
141+
*
142+
* @return Void
143+
*/
132144
public function custom_cron_hook_cb() {
133145

134-
add_action('custom_cron_hook', array( $this, 'do_cron_job_function'));
146+
add_action( 'custom_cron_hook', array( $this, 'do_cron_job_function' ) );
135147
}
136148

137149

150+
/**
151+
* Uninstall CRON hook
152+
*
153+
* @return Void
154+
*/
138155
public function cron_uninstall() {
139156

140-
wp_clear_scheduled_hook('custom_cron_hook');
157+
wp_clear_scheduled_hook( 'custom_cron_hook' );
141158
}
142159

143160

144-
//Include scripts
161+
/**
162+
* Include scripts
163+
*
164+
* @return Void
165+
*/
145166
public function scripts() {
146167

147168
if ( class_exists( 'PLUGIN_SCRIPT' ) ) new PLUGIN_SCRIPT();
148169
}
149170

150171

151-
152-
//Include settings pages
172+
/**
173+
* Include settings pages
174+
*
175+
* @return Void
176+
*/
153177
public function settings() {
154178

155179
if ( class_exists( 'PLUGIN_SETTINGS' ) ) new PLUGIN_SETTINGS();
156180
}
157181

158182

159-
//Include widget classes
183+
/**
184+
* Include widget classes
185+
*
186+
* @return Void
187+
*/
160188
public function widgets() {
161189

162190
if ( class_exists( 'PLUGIN_WIDGET' ) ) new PLUGIN_WIDGET();
163191
}
164192

165193

166-
167-
//Include metabox classes
194+
/**
195+
*Include metabox classes
196+
*
197+
* @return Void
198+
*/
168199
public function metabox() {
169200

170201
if ( class_exists( 'PLUGIN_METABOX' ) ) new PLUGIN_METABOX();
171202
}
172203

173204

174-
175-
//Include shortcode classes
205+
/**
206+
* Include shortcode classes
207+
*
208+
* @return Void
209+
*/
176210
public function shortcode() {
177211

178212
if ( class_exists( 'PLUGIN_SHORTCODE' ) ) new PLUGIN_SHORTCODE();
179213
}
180214

181215

182-
183-
//Add functionality files
216+
/**
217+
* Add the functionality files
218+
* Available classes: PLUGIN_INSTALL, PLUGIN_DB, PLUGIN_METABOX, PLUGIN_QUERY, PLUGIN_SETTINGS, PLUGIN_SHORTCODE, PLUGIN_WIDGET
219+
*
220+
* @return Void
221+
*/
184222
public function functionality() {
185223

186-
require_once ('src/install.php');
187-
require_once ('src/db.php');
188-
require_once ('src/query.php');
189-
require_once ('src/settings.php');
190-
require_once ('src/widget.php');
191-
require_once ('src/metabox.php');
192-
require_once ('src/shortcode.php');
224+
require_once( 'src/install.php' );
225+
require_once( 'src/db.php' );
226+
require_once( 'src/query.php' );
227+
require_once( 'src/settings.php' );
228+
require_once( 'src/widget.php' );
229+
require_once( 'src/metabox.php' );
230+
require_once( 'src/shortcode.php' );
193231
}
194232

195233

196-
197-
//Call the dependency files
234+
/**
235+
* Call the dependency files
236+
* Available classes: PLUGIN_CORN, PLUGIN_API, PLUGIN_TABLE, PLUGIN_AJAX, PLUGIN_UPLOAD, PLUGIN_SCRIPT
237+
*
238+
* @return Void
239+
*/
198240
public function helpers() {
199241

200-
require_once ('lib/cron.php');
201-
require_once ('lib/api.php');
202-
require_once ('lib/table.php');
203-
require_once ('lib/ajax.php');
204-
require_once ('lib/upload.php');
205-
require_once ('lib/script.php');
206-
207-
/**
208-
* Available classes:
209-
*
210-
* PLUGIN_CORN, PLUGIN_API, PLUGIN_TABLE, PLUGIN_AJAX, PLUGIN_UPLOAD, PLUGIN_SCRIPT
211-
*/
242+
require_once( 'lib/cron.php' );
243+
require_once( 'lib/api.php' );
244+
require_once( 'lib/table.php' );
245+
require_once( 'lib/ajax.php' );
246+
require_once( 'lib/upload.php' );
247+
require_once( 'lib/script.php' );
212248
}
213249

214250

215-
251+
/**
252+
* Instantiate the plugin
253+
*
254+
* @return Void
255+
*/
216256
public function __construct() {
217257

218258
$this->helpers();
219259
$this->functionality();
220260

221261
register_activation_hook( PLUGIN_FILE, array( $this, 'db_install' ) );
222-
register_activation_hook( PLUGIN_FILE, array($this, 'cron_activation' ));
262+
register_activation_hook( PLUGIN_FILE, array($this, 'cron_activation' ) );
223263

224-
//remove the DB upon uninstallation
225-
register_uninstall_hook( PLUGIN_FILE, array( 'PLUGIN_BUILD', 'db_uninstall' ) ); //$this won't work here.
264+
//remove the DB and CORN upon uninstallation
265+
//$this won't work here.
266+
register_uninstall_hook( PLUGIN_FILE, array( 'PLUGIN_BUILD', 'db_uninstall' ) );
226267
register_uninstall_hook( PLUGIN_FILE, array( 'PLUGIN_BUILD', 'cron_uninstall' ) );
227268

228-
add_action('init', array($this, 'installation'));
229-
add_action('init', array($this, 'custom_cron_hook_cb'));
269+
add_action( 'init', array( $this, 'installation' ) );
270+
add_action( 'init', array( $this, 'custom_cron_hook_cb' ) );
230271

231272
$this->scripts();
232273
$this->widgets();

0 commit comments

Comments
 (0)