Skip to content

Commit 4586c26

Browse files
committed
Added PostTypes_Loader class
1 parent e606f3d commit 4586c26

4 files changed

Lines changed: 42 additions & 10 deletions

File tree

app/Plugin.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ public function load_plugin() {
6060
// Enqueue scripts and stylesheets
6161
new EnqueueScripts();
6262

63-
// Perform core plugin logic
64-
new Core();
65-
6663
// Create custom post types
67-
new PostTypes\Clients();
64+
new PostTypes\PostTypes_Loader();
6865

6966
// Load custom widgets
70-
new Widgets\WidgetLoader();
67+
new Widgets\Widget_Loader();
7168

7269
// Load shortcodes
7370
new Shortcodes\Shortcode_Loader();
7471

72+
// Perform core plugin logic
73+
new Core();
74+
7575
}
7676

7777
/**

app/PostTypes/PostTypes_Loader.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
namespace VendorName\PluginName\PostTypes;
3+
use VendorName\PluginName\Plugin;
4+
5+
class PostTypes_Loader extends Plugin {
6+
7+
/**
8+
* @var array Shortcode class name to register
9+
* @since 0.4.0
10+
*/
11+
protected $posttypes;
12+
13+
public function __construct() {
14+
15+
$this->posttypes = array(
16+
Clients::class
17+
);
18+
19+
foreach( $this->posttypes as $posttypesClass ) {
20+
21+
$posttype = new $posttypesClass();
22+
if( $posttype instanceof PostTypeInterface ) {
23+
new $posttype();
24+
}
25+
26+
}
27+
28+
}
29+
30+
}

app/Shortcodes/Shortcode_Loader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public function __construct() {
2121

2222
$shortcode = new $shortcodeClass();
2323
if( $shortcode instanceof ShortcodeInterface ) {
24-
new $shortcode();
24+
new $shortcode();
2525
} else {
26-
// Log or show error notices
26+
// Log or show error notices
2727
}
2828

2929
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
namespace VendorName\PluginName\Widgets;
33
use VendorName\PluginName\Plugin;
44

5-
class WidgetLoader extends Plugin {
5+
class Widget_Loader extends Plugin {
66

77
public function __construct() {
88

99
// Register widgets
1010
add_action( 'widgets_init', function () {
11-
register_widget( new ExampleWidget() );
12-
} );
11+
12+
register_widget( new Example_Widget() );
13+
14+
});
1315

1416
}
1517

0 commit comments

Comments
 (0)