-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdilaz-demo-plugin.php
209 lines (170 loc) · 4.6 KB
/
dilaz-demo-plugin.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
<?php
/**
* Plugin Name: Dilaz Demo Plugin
* Plugin URI: https://github.com/Rodgath/dilaz-demo-plugin
* Description: A sample plugin showing how to implement dilaz panel and dilaz metabox in a WordPress plugin.
* Version: 1.0
* Author: Rodgath
* Author URI: Rodgath.com
* Text Domain: dilaz-demo-plugin
* Domain Path: /languages
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation. You cannot use any
* other versions of the License except version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
/*
* Exit if accessed directly
*/
defined('ABSPATH') || exit('No Dice!');
/*
* Main Class
*
*/
class n00bPluginName {
public function __construct() {
add_action( 'plugins_loaded', array($this, 'init') );
add_action( 'admin_menu', array($this, 'admin_menu') );
add_action( 'wp_enqueue_scripts', array($this, 'enqueue_scripts') );
add_action( 'admin_enqueue_scripts', array($this, 'admin_enqueue_scripts') );
register_activation_hook( __FILE__, array($this, 'activation') );
register_deactivation_hook( __FILE__, array($this, 'deactivation') );
register_uninstall_hook( __FILE__, array($this, 'uninstallation') );
}
/**
* Initialize the plugin
*
* @since 1.0
*/
public function init() {
/* Load constants */
$this->constants();
/* Load the text domain for translations */
$this->i18n();
/* Load admin functions */
$this->backend();
/* Load files needed by the plugin */
$this->includes();
}
/**
* Enqueue plugin frontend scripts
*
* @since 1.0
*/
public function enqueue_scripts() {
/* Frontend styles */
wp_enqueue_style('n00b-style', N00B_URL . 'assets/css/style.css');
/* Frontend scripts */
wp_enqueue_script('n00b-script', N00B_URL . 'assets/js/script.js', array('jquery'), null, true);
/* Frontend script localization */
wp_localize_script('n00b-script', 'n00b_l10n',
array(
'site_name' => __('n00b Site', 'plugin-text-domain'),
'n00b_url' => N00B_URL,
'n00b_dir' => N00B_DIR,
'site_url' => site_url(),
)
);
}
/**
* Enqueue plugin admin scripts
*
* @since 1.0
*/
public function admin_enqueue_scripts() {
/* Ensure that the scripts load only in portfolio post type page */
if ('portfolio' != get_current_screen()->post_type) return;
/* Admin styles */
wp_enqueue_style('n00b-admin-style', N00B_URL . 'assets/css/admin-style.css', null, null);
/* Admin scripts */
wp_enqueue_script('n00b-admin-script', N00B_URL . 'assets/js/admin-script.js', array('jquery'), null, true);
/* Admin script localization */
wp_localize_script('n00b-admin-script', 'n00b_admin_l10n',
array(
'site_name' => __('n00b Site', 'plugin-text-domain'),
'n00b_url' => N00B_URL,
'n00b_dir' => N00B_DIR,
'admin_url' => admin_url(),
)
);
}
/**
* Plugin admin menu
*
* @since 1.0
*/
public function admin_menu() {
}
/**
* Define onstants
*
* @since 1.0
* @return void
*/
public function constants() {
define('N00B_URL', trailingslashit(plugin_dir_url(__FILE__)));
define('N00B_DIR', trailingslashit(plugin_dir_path(__FILE__)));
}
/**
* Set the locale for the plugin internationlization.
*
* @since 1.0
*/
public function i18n() {
load_plugin_textDomain('plugin-name', false, N00B_DIR . 'languages/');
}
/**
* Admin functions - Options panel, metabox options etc
*
* @since 1.0
*/
public function backend() {
}
/**
* Plugin includes
*
* @since 1.0
* @return void
*/
public function includes() {
/* Dilaz admin options panel */
require_once 'dilaz-panel-options/admin.php';
/* Dilaz metabox options */
require_once 'dilaz-metabox-options/metabox.php';
}
/**
* Plugin activation
* This is called when plugin is activated.
*
* @since 1.0
*/
public function activation() {
}
/**
* Plugin deactivation
* This is called when plugin is deactivated.
* Contains all the code that should run when the plugin is deactivated.
*
* @since 1.0
*/
public function deactivation() {
}
/**
* Plugin uninstallation
* This is called when plugin is uninstalled.
* Contains all the code that should run when the plugin is unsinstalled.
*
* @since 1.0
*/
public function uninstallation() {
}
}
new n00bPluginName;