Skip to content

Commit 6b3fdcf

Browse files
committed
2 parents 0621086 + 82cae02 commit 6b3fdcf

12 files changed

+157
-104
lines changed

inc/class-block-bindings.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace {{namespace|lowerCase}}\classes;
3+
24
/**
35
* Block Bindings Registration.
46
*
@@ -13,7 +15,7 @@
1315
/**
1416
* Block Bindings class.
1517
*/
16-
class {{namespace|pascalCase}}_Block_Bindings {
18+
class Block_Bindings {
1719

1820
/**
1921
* Binding source name.

inc/class-block-templates.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace {{namespace|lowerCase}}\classes;
3+
24
/**
35
* Block Templates Registration.
46
*
@@ -12,7 +14,7 @@
1214
/**
1315
* Block Templates class.
1416
*/
15-
class {{namespace|pascalCase}}_Block_Templates {
17+
class Block_Templates {
1618

1719
/**
1820
* Constructor.

inc/class-core.php

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
namespace {{namespace|lowerCase}}\classes;
3+
4+
/**
5+
* Core Class intiating the rest of the classes.
6+
*
7+
* @package {{namespace}}
8+
*/
9+
10+
if ( ! defined( 'ABSPATH' ) ) {
11+
exit;
12+
}
13+
14+
/**
15+
* Main plugin class.
16+
*/
17+
class Core {
18+
19+
/**
20+
* Constructor.
21+
*/
22+
public function __construct() {
23+
$this->load_classes();
24+
25+
add_action( 'init', array( $this, 'init' ) );
26+
add_action( 'init', array( $this, 'register_blocks' ) );
27+
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
28+
29+
// Initialize components.
30+
new Post_Types();
31+
new Taxonomies();
32+
new Fields();
33+
new Repeater_Fields();
34+
new Options();
35+
new SCF_JSON();
36+
new Block_Templates();
37+
new Block_Bindings();
38+
new Patterns();
39+
}
40+
41+
/**
42+
* Load the plugin classes.
43+
*
44+
* @return void
45+
*/
46+
public function load_classes() {
47+
// Include core classes.
48+
require_once {{namespace|upper}}_PLUGIN_DIR . 'inc/class-post-types.php';
49+
require_once {{namespace|upper}}_PLUGIN_DIR . 'inc/class-taxonomies.php';
50+
require_once {{namespace|upper}}_PLUGIN_DIR . 'inc/class-fields.php';
51+
require_once {{namespace|upper}}_PLUGIN_DIR . 'inc/class-repeater-fields.php';
52+
require_once {{namespace|upper}}_PLUGIN_DIR . 'inc/class-options.php';
53+
require_once {{namespace|upper}}_PLUGIN_DIR . 'inc/class-scf-json.php';
54+
require_once {{namespace|upper}}_PLUGIN_DIR . 'inc/class-block-templates.php';
55+
require_once {{namespace|upper}}_PLUGIN_DIR . 'inc/class-block-bindings.php';
56+
require_once {{namespace|upper}}_PLUGIN_DIR . 'inc/class-patterns.php';
57+
}
58+
59+
/**
60+
* Initialize the plugin.
61+
*
62+
* @return void
63+
*/
64+
public function init() {
65+
// Register block category.
66+
add_filter( 'block_categories_all', array( $this, 'register_block_category' ) );
67+
}
68+
69+
/**
70+
* Register blocks from the blocks directory.
71+
*
72+
* @return void
73+
*/
74+
public function register_blocks() {
75+
// Auto-register all blocks in src/blocks/.
76+
$blocks_dir = {{namespace|upper}}_PLUGIN_DIR . 'build/blocks/';
77+
78+
if ( is_dir( $blocks_dir ) ) {
79+
$blocks = glob( $blocks_dir . '*/block.json' );
80+
81+
foreach ( $blocks as $block_json ) {
82+
register_block_type( dirname( $block_json ) );
83+
}
84+
}
85+
}
86+
87+
/**
88+
* Register custom block category.
89+
*
90+
* @param array $categories Existing block categories.
91+
* @return array Modified block categories.
92+
*/
93+
public function register_block_category( $categories ) {
94+
return array_merge(
95+
array(
96+
array(
97+
'slug' => '{{slug}}',
98+
'title' => __( '{{name}}', '{{textdomain}}' ),
99+
'icon' => 'admin-generic',
100+
),
101+
),
102+
$categories
103+
);
104+
}
105+
106+
/**
107+
* Load plugin text domain for translations.
108+
*
109+
* @return void
110+
*/
111+
public function load_textdomain() {
112+
load_plugin_textdomain(
113+
'{{textdomain}}',
114+
false,
115+
dirname( {{namespace|upper}}_PLUGIN_BASENAME ) . '/languages'
116+
);
117+
}
118+
}

inc/class-fields.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace {{namespace|lowerCase}}\classes;
3+
24
/**
35
* Custom Fields Registration using Secure Custom Fields.
46
*
@@ -13,7 +15,7 @@
1315
/**
1416
* Fields class.
1517
*/
16-
class {{namespace|pascalCase}}_Fields {
18+
class Fields {
1719

1820
/**
1921
* Field group key.

inc/class-options.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace {{namespace|lowerCase}}\classes;
3+
24
/**
35
* Options Pages Registration using Secure Custom Fields.
46
*
@@ -19,7 +21,7 @@
1921
*
2022
* Registers options pages and their associated field groups using SCF.
2123
*/
22-
class {{namespace|pascalCase}}_Options {
24+
class Options {
2325

2426
/**
2527
* Main options page slug.

inc/class-patterns.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace {{namespace|lowerCase}}\classes;
3+
24
/**
35
* Block Patterns Registration.
46
*
@@ -12,7 +14,7 @@
1214
/**
1315
* Patterns class.
1416
*/
15-
class {{namespace|pascalCase}}_Patterns {
17+
class Patterns {
1618

1719
/**
1820
* Constructor.

inc/class-post-types.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace {{namespace|lowerCase}}\classes;
3+
24
/**
35
* Custom Post Type Registration.
46
*
@@ -12,7 +14,7 @@
1214
/**
1315
* Post Types class.
1416
*/
15-
class {{namespace|pascalCase}}_Post_Types {
17+
class Post_Types {
1618

1719
/**
1820
* Post type slug.

inc/class-repeater-fields.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace {{namespace|lowerCase}}\classes;
3+
24
/**
35
* Repeater and Flexible Content Fields using Secure Custom Fields.
46
*
@@ -13,7 +15,7 @@
1315
/**
1416
* Repeater Fields class.
1517
*/
16-
class {{namespace|pascalCase}}_Repeater_Fields {
18+
class Repeater_Fields {
1719

1820
/**
1921
* Constructor.

inc/class-scf-json-validator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace {{namespace|lowerCase}}\classes;
3+
24
/**
35
* SCF JSON Schema Validator.
46
*
@@ -18,7 +20,7 @@
1820
*
1921
* Validates SCF field group JSON files against the schema.
2022
*/
21-
class {{namespace|pascalCase}}_SCF_JSON_Validator {
23+
class SCF_JSON_Validator {
2224

2325
/**
2426
* Path to the JSON schema file.

inc/class-scf-json.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
namespace {{namespace|lowerCase}}\classes;
3+
24
/**
35
* SCF Local JSON Configuration.
46
*
@@ -19,7 +21,7 @@
1921
*
2022
* Manages Local JSON save and load paths for SCF field groups.
2123
*/
22-
class {{namespace|pascalCase}}_SCF_JSON {
24+
class SCF_JSON {
2325

2426
/**
2527
* Local JSON directory path.

0 commit comments

Comments
 (0)