-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathppb-module-boilerplate.php
226 lines (186 loc) · 5.73 KB
/
ppb-module-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
<?php
/*
Plugin Name: Pootle Page Builder Module Boilerplate
Plugin URI: http://pootlepress.com/
Description: A simple single class boilerplate for fast track Pootle Page Builder Module Development
Author: Shramee
Version: 1.0.0
Author URI: http://shramee.com/
@developer shramee <[email protected]>
*/
class PPB_Module_Boilerplate {
/** @var string Token */
public $token = 'ppb-module-biolerplate';
/** @var string Main plugin class, Module is greyed out if this class is not present */
public $class = 'PPB_Module_Boilerplate';
/** @var string Module name */
public $name = 'Module Boilerplate';
/** @var PPB_Module_Boilerplate Instance */
private static $_instance = null;
/**
* Gets PPB_Module_Boilerplate instance
* @return PPB_Module_Boilerplate instance
* @since 1.0.0
*/
public static function instance() {
if ( null == self::$_instance ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* PootlePB_Meta_Slider constructor.
*/
public function __construct() {
add_action( 'init', array( $this, 'init', ) );
}
/**
* Initiates the addon
* @action init
*/
public function init() {
// Adding modules to live editor sidebar
add_action( 'pootlepb_modules', array( $this, 'module' ) );
// Adding modules plugin to Modules page
add_action( 'pootlepb_modules_page', array( $this, 'module_plugin' ), 25 );
if ( class_exists( $this->class ) ) {
// Adding module tab in content block panel
add_filter( 'pootlepb_content_block_tabs', array( $this, 'tab' ) );
add_filter( 'pootlepb_le_content_block_tabs', array( $this, 'tab' ) );
// Adding stuff to the content block
add_action( 'pootlepb_render_content_block', array( $this, 'content' ), 52 );
// Content block panel fields
add_filter( 'pootlepb_content_block_fields', array( $this, 'fields' ) );
$forms = ninja_forms_get_all_forms();
foreach ( $forms as $form ) {
$this->choices[ $form['id'] ] = "$form[id] - $form[name]";
}
}
}
/**
* The module box data
* @param array $mods Modules
* @return array
* @filter pootlepb_modules
*/
public function module( $mods ) {
$mods["$this->token-form"] = array(
'label' => $this->name,
'icon_class' => 'dashicons dashicons-admin-plugins',
'icon_html' => '',
'tab' => "#pootle-$this->token-tab",
'ActiveClass' => $this->class,
'priority' => 35,
);
return $mods;
}
/**
* USE THIS ONLY IF YOUR MODULE NEEDS AN EXTERNAL PLUGIN TO WORK
*
* Adds plugin entry in Free modules section
* @param array $mods Modules
* @return mixed
* @filter pootlepb_modules_page
*/
public function module_plugin( $mods ) {
$mods[ $this->token ] = array(
'Name' => $this->name,
'Description' => 'Awesome boilerplate to fast track your Pootle Pagebuilder module development.',
'InstallURI' => 'http://example.com/',
//'InstallURI' => admin_url( "/plugin-install.php?s=$this->name&tab=search&type=term" ), // If parent plugin hosted on WP.org
'AuthorURI' => 'https://shramee.me',
'Author' => 'Shramee',
'Image' => plugin_dir_url( __FILE__ ) . '/module.png',
//'Image' => "//ps.w.org/$this->token/assets/icon-256x256.png?rev=1262610", // If parent plugin hosted on WP.org
'ActiveClass' => $this->class,
);
return $mods;
}
/**
* Adds module tab in content block panel
* @param array $tabs Content block panel tabs
* @return mixed
* @filter pootlepb_content_block_tabs, pootlepb_le_content_block_tabs
*/
public function tab( $tabs ) {
$tabs[ $this->token ] = array(
'label' => $this->name,
'priority' => 5,
);
return $tabs;
}
/**
* Adds module fields in content block panel
* @param $fields
* @return mixed
* @filter pootlepb_content_block_fields
*/
public function fields( $fields ) {
$fields[ $this->token . '-txt' ] = array(
'name' => 'Sample text field',
'type' => 'text',
'tab' => $this->token,
);
$fields[ $this->token . '-clr' ] = array(
'name' => 'Sample color field',
'type' => 'color',
'tab' => $this->token,
);
return $fields;
}
/**
* Renders the module content
* @param array $info Content block info
* @action pootlepb_render_content_block
*/
public function content( $info ) {
$set = json_decode( $info['info']['style'], true ); // Here are all the settings
if ( ! empty( $set[ $this->token . '-txt' ] ) ) {
// Output your module content here
echo "<div style='color: {$set[ $this->token . '-clr' ]}'>{$set[ $this->token . '-txt' ]}</div>";
}
}
}
PPB_Module_Boilerplate::instance();
?>
### `PPB_Module_Boilerplate`::`instance()`
* Gets PPB_Module_Boilerplate instance
* @return PPB_Module_Boilerplate instance
* @since 1.0.0
-------
### `PPB_Module_Boilerplate`::`__construct()`
* PootlePB_Meta_Slider constructor.
-------
### `PPB_Module_Boilerplate`::`init()`
* Initiates the addon
* @action init
-------
### `PPB_Module_Boilerplate`::`module( $mods )`
* The module box data
* @param array $mods Modules
* @return array
* @filter pootlepb_modules
-------
### `PPB_Module_Boilerplate`::`module_plugin( $mods )`
* USE THIS ONLY IF YOUR MODULE NEEDS AN EXTERNAL PLUGIN TO WORK
* Adds plugin entry in Free modules section
* @param array $mods Modules
* @return mixed
* @filter pootlepb_modules_page
-------
### `PPB_Module_Boilerplate`::`tab( $tabs )`
* Adds module tab in content block panel
* @param array $tabs Content block panel tabs
* @return mixed
* @filter pootlepb_content_block_tabs, pootlepb_le_content_block_tabs
-------
### `PPB_Module_Boilerplate`::`fields( $fields )`
* Adds module fields in content block panel
* @param $fields
* @return mixed
* @filter pootlepb_content_block_fields
-------
### `PPB_Module_Boilerplate`::`content( $info )`
* Renders the module content
* @param array $info Content block info
* @action pootlepb_render_content_block