PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.7
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.7
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 2.6.1 2.7.0 All 28 releases
← All changes | includes/class.plugin.php +22 -3 2.7.52.7.7 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 /**
@@ -164,9 +164,9 @@
164 164 * @return void
165 165 */
166 166 public function activation_hook() {
167 167 // Add custom capabilities to administrator role.
168 - $this->snippets_type->add_capabilities();
168 + $this->get_snippets_type()->add_capabilities();
169 169
170 170 // Create demo snippets with examples of use.
171 171 if ( ! get_option( 'wbcr_inp_demo_snippets_created' ) ) {
172 172 WINP_Helper::create_demo_snippets();
@@ -182,9 +182,28 @@
182 182 * @return void
183 183 */
184 184 public function deactivation_hook() {
185 185 // Remove custom capabilities from administrator role.
186 - $this->snippets_type->remove_capabilities();
186 + $this->get_snippets_type()->remove_capabilities();
187 + }
188 +
189 + /**
190 + * Get the snippets post type handler, loading it on demand.
191 + *
192 + * The (de)activation hooks can run outside of admin/REST requests
193 + * (e.g. `wp plugin activate` via WP-CLI), where load_backend() and
194 + * therefore register_types() never ran.
195 + *
196 + * @return WINP_SnippetsType
197 + */
198 + private function get_snippets_type() {
199 + if ( is_null( $this->snippets_type ) ) {
200 + require_once WINP_PLUGIN_DIR . '/admin/includes/class.snippets.viewtable.php';
201 + require_once WINP_PLUGIN_DIR . '/admin/types/snippets-post-types.php';
202 + $this->snippets_type = new WINP_SnippetsType();
203 + }
204 +
205 + return $this->snippets_type;
187 206 }
188 207
189 208 /**
190 209 * Register custom post types and taxonomies.