@@ -50,101 +50,16 @@ function () {
5050 return ;
5151}
5252
53- // Include core classes.
54- require_once {{namespace |upper }}_PLUGIN_DIR . 'inc/class-post-types.php ' ;
55- require_once {{namespace |upper }}_PLUGIN_DIR . 'inc/class-taxonomies.php ' ;
56- require_once {{namespace |upper }}_PLUGIN_DIR . 'inc/class-fields.php ' ;
57- require_once {{namespace |upper }}_PLUGIN_DIR . 'inc/class-repeater-fields.php ' ;
58- require_once {{namespace |upper }}_PLUGIN_DIR . 'inc/class-options.php ' ;
59- require_once {{namespace |upper }}_PLUGIN_DIR . 'inc/class-scf-json.php ' ;
60- require_once {{namespace |upper }}_PLUGIN_DIR . 'inc/class-block-templates.php ' ;
61- require_once {{namespace |upper }}_PLUGIN_DIR . 'inc/class-block-bindings.php ' ;
62- require_once {{namespace |upper }}_PLUGIN_DIR . 'inc/class-patterns.php ' ;
63-
6453/**
65- * Main plugin class.
54+ * Initiate an instance of our plugin.
55+ *
56+ * @return {{namespace|lowerCase}}_plugin();
6657 */
67- class {{namespace |pascalCase }}_Plugin {
68-
69- /**
70- * Constructor.
71- */
72- public function __construct () {
73- add_action ( 'init ' , array ( $ this , 'init ' ) );
74- add_action ( 'init ' , array ( $ this , 'register_blocks ' ) );
75- add_action ( 'plugins_loaded ' , array ( $ this , 'load_textdomain ' ) );
76-
77- // Initialize components.
78- new \{{namespace |lowerCase }}\classes \Post_Types ();
79- new \{{namespace |lowerCase }}\classes \Taxonomies ();
80- new \{{namespace |lowerCase }}\classes \Fields ();
81- new \{{namespace |lowerCase }}\classes \Repeater_Fields ();
82- new \{{namespace |lowerCase }}\classes \Options ();
83- new \{{namespace |lowerCase }}\classes \SCF_JSON ();
84- new \{{namespace |lowerCase }}\classes \Block_Templates ();
85- new \{{namespace |lowerCase }}\classes \Block_Bindings ();
86- new \{{namespace |lowerCase }}\classes \Patterns ();
87- }
88-
89- /**
90- * Initialize the plugin.
91- *
92- * @return void
93- */
94- public function init () {
95- // Register block category.
96- add_filter ( 'block_categories_all ' , array ( $ this , 'register_block_category ' ) );
97- }
98-
99- /**
100- * Register blocks from the blocks directory.
101- *
102- * @return void
103- */
104- public function register_blocks () {
105- // Auto-register all blocks in src/blocks/.
106- $ blocks_dir = {{namespace |upper}}_PLUGIN_DIR . 'build/blocks/ ' ;
107-
108- if ( is_dir ( $ blocks_dir ) ) {
109- $ blocks = glob ( $ blocks_dir . '*/block.json ' );
110-
111- foreach ( $ blocks as $ block_json ) {
112- register_block_type ( dirname ( $ block_json ) );
113- }
114- }
115- }
116-
117- /**
118- * Register custom block category.
119- *
120- * @param array $categories Existing block categories.
121- * @return array Modified block categories.
122- */
123- public function register_block_category ( $ categories ) {
124- return array_merge (
125- array (
126- array (
127- 'slug ' => '{{slug}} ' ,
128- 'title ' => __ ( '{{name}} ' , '{{textdomain}} ' ),
129- 'icon ' => 'admin-generic ' ,
130- ),
131- ),
132- $ categories
133- );
134- }
135-
136- /**
137- * Load plugin text domain for translations.
138- *
139- * @return void
140- */
141- public function load_textdomain () {
142- load_plugin_textdomain (
143- '{{textdomain}} ' ,
144- false ,
145- dirname ( {{namespace |upper}}_PLUGIN_BASENAME ) . '/languages '
146- );
58+ function {{namespace |lowerCase }}_plugin () {
59+ global $ {{namespace|lowerCase}}_plugin;
60+ if ( null === $ {{namespace|lowerCase}}_plugin ) {
61+ $ {{namespace|lowerCase}}_plugin = new \{{namespace |lowerCase }}\classes \Core ();
14762 }
63+ return $ {{namespace|lowerCase}}_plugin;
14864}
149-
150- new {{namespace |pascalCase }}_Plugin ();
65+ {{namespace |lowerCase }}_plugin ();
0 commit comments