PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.8
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.8
2.7.9 2.7.8 2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 All 30 releases
← All changes | includes/class.plugin.php +25 -3 2.7.4 → 2.7.8 View file →
@@ -28,9 +28,9 @@
28 28
29 29 /**
30 30 * Snippets custom post type instance.
31 31 *
32 - * @var WINP_SnippetsType
32 + * @var WINP_SnippetsType|null
33 33 */
34 34 private $snippets_type;
35 35
36 36 /**
@@ -45,8 +45,11 @@
45 45
46 46 require_once WINP_PLUGIN_DIR . '/includes/class.rest.php';
47 47 new WINP_Rest();
48 48
49 + require_once WINP_PLUGIN_DIR . '/includes/class.abilities.php';
50 + new WINP_Abilities();
51 +
49 52 require_once WINP_PLUGIN_DIR . '/admin/pages/class.settings.php';
50 53 require_once WINP_PLUGIN_DIR . '/admin/pages/class.new-item.php';
51 54 require_once WINP_PLUGIN_DIR . '/admin/pages/class.snippet-library.php';
52 55
@@ -164,9 +167,9 @@
164 167 * @return void
165 168 */
166 169 public function activation_hook() {
167 170 // Add custom capabilities to administrator role.
168 - $this->snippets_type->add_capabilities();
171 + $this->get_snippets_type()->add_capabilities();
169 172
170 173 // Create demo snippets with examples of use.
171 174 if ( ! get_option( 'wbcr_inp_demo_snippets_created' ) ) {
172 175 WINP_Helper::create_demo_snippets();
@@ -182,9 +185,28 @@
182 185 * @return void
183 186 */
184 187 public function deactivation_hook() {
185 188 // Remove custom capabilities from administrator role.
186 - $this->snippets_type->remove_capabilities();
189 + $this->get_snippets_type()->remove_capabilities();
190 + }
191 +
192 + /**
193 + * Get the snippets post type handler, loading it on demand.
194 + *
195 + * The (de)activation hooks can run outside of admin/REST requests
196 + * (e.g. `wp plugin activate` via WP-CLI), where load_backend() and
197 + * therefore register_types() never ran.
198 + *
199 + * @return WINP_SnippetsType
200 + */
201 + private function get_snippets_type() {
202 + if ( is_null( $this->snippets_type ) ) {
203 + require_once WINP_PLUGIN_DIR . '/admin/includes/class.snippets.viewtable.php';
204 + require_once WINP_PLUGIN_DIR . '/admin/types/snippets-post-types.php';
205 + $this->snippets_type = new WINP_SnippetsType();
206 + }
207 +
208 + return $this->snippets_type;
187 209 }
188 210
189 211 /**
190 212 * Register custom post types and taxonomies.