forked from theantichris/WordPress-Plugin-Boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordpress-plugin-boilerplate.php
96 lines (73 loc) · 2.27 KB
/
wordpress-plugin-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
<?php
/*
Plugin Name: WordPress Plugin Boilerplate
Plugin URI: https://github.com/theantichris/wordpress-plugin-boilerplate
Description: An object oriented boilerplate for developing a WordPress plugin.
Version: 6.0.0
Author: Christopher Lamm
Author URI: http://www.theantichris.com
License: GPL V3
*/
class WordPress_Plugin_Boilerplate {
private static $instance = null;
private $plugin_path;
private $plugin_url;
private $text_domain = '';
/**
* Creates or returns an instance of this class.
*/
public static function get_instance() {
// If an instance hasn't been created and set to $instance create an instance and set it to $instance.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Initializes the plugin by setting localization, hooks, filters, and administrative functions.
*/
private function __construct() {
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->plugin_url = plugin_dir_url( __FILE__ );
load_plugin_textdomain( $this->text_domain, false, $this->plugin_path . '/lang' );
add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'register_styles' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'register_styles' ) );
register_activation_hook( __FILE__, array( $this, 'activation' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
$this->run_plugin();
}
public function get_plugin_url() {
return $this->plugin_url;
}
public function get_plugin_path() {
return $this->plugin_path;
}
/**
* Place code that runs at plugin activation here.
*/
public function activation() {
}
/**
* Place code that runs at plugin deactivation here.
*/
public function deactivation() {
}
/**
* Enqueue and register JavaScript files here.
*/
public function register_scripts() {
}
/**
* Enqueue and register CSS files here.
*/
public function register_styles() {
}
/**
* Place code for your plugin's functionality here.
*/
private function run_plugin() {
}
}
WordPress_Plugin_Boilerplate::get_instance();