├── readme.md
└── wordpress-plugin-simple-boilerplate.php
/readme.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | #WordPress Plugin Boilerplate#
10 |
11 | * Contributors: Webby Scots
12 | * License: GPLv2 or later
13 | * License URI: http://www.gnu.org/licenses/gpl-2.0.html
14 |
15 | Use this to make your WordPress plugins.
16 |
17 | ## Installation and Usage
18 |
19 | 1. Clone the repo
20 | 2. Code :-)
21 |
22 | It has its own autoloader. All you need to do is create an includes folder and add the class files using add class-mypluginname-classname.php. And then in the init function do:
23 |
24 | ```if ($this_condition) {
25 | $this->classname = new MyPluginName_ClassName();
26 | }```
27 |
28 | The part after new is what is searched for, as lowercase and with underscores as dashes in the includes folder, but the class- part is prefixed for you.
--------------------------------------------------------------------------------
/wordpress-plugin-simple-boilerplate.php:
--------------------------------------------------------------------------------
1 | required_plugins))
21 | return true;
22 | $active_plugins = (array) get_option('active_plugins', array());
23 | if (is_multisite()) {
24 | $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
25 | }
26 | foreach ($this->required_plugins as $key => $required) {
27 | $required = (!is_numeric($key)) ? "{$key}/{$required}.php" : "{$required}/{$required}.php";
28 | if (!in_array($required, $active_plugins) && !array_key_exists($required, $active_plugins))
29 | return false;
30 | }
31 | return true;
32 | }
33 |
34 | function __construct() {
35 | if (!$this->have_required_plugins())
36 | return;
37 | load_plugin_textdomain($this->textdomain, false, dirname(plugin_basename(__FILE__)) . '/languages');
38 | spl_autoload_register(array($this,'autoload'));
39 | $this->init();
40 | }
41 |
42 | private function init() {
43 |
44 | }
45 |
46 | /* Autoload Classes */
47 | function autoload($class) {
48 | $class = strtolower(str_replace("_","-",$class));
49 | $class_file = untrailingslashit(plugin_dir_path(__FILE__)) ."/includes/class-{$class}.php";
50 | if (file_exists($class_file)) {
51 | include_once($class_file);
52 | }
53 | }
54 |
55 | public static function instance() {
56 | if (is_null(self::$_instance)) {
57 | self::$_instance = new self();
58 | }
59 | return self::$_instance;
60 | }
61 | }
62 |
63 | /* Use this function to call up the class from anywahere
64 | like PB()->class_method();
65 | */
66 | function PB() {
67 | return PB::instance();
68 | }
69 |
70 | PB();
71 |
--------------------------------------------------------------------------------