-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.php
More file actions
126 lines (114 loc) · 4.9 KB
/
Copy pathmodule.php
File metadata and controls
126 lines (114 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
if ( ! class_exists( 'MK_Module', false ) ) {
/**
* MK Module Kit
*
* Template module for building actual Module Kit modules
*
* @author Garret McGraw-Hanson
* @version 0.10.0
*
* @property bool $is_root overrideable Whether the module is a Root Module or Submodule
* @property string $key Identification key of the module (ie mk_example)
* @property object $options_page MK_Module_Kit_Options object
* @property string $path Path to this class from plugin root
* @property string $prefix overrideable Module naming prefix
* @property string $title overrideable Module display title (ie MK Example)
*
* @static object get_instance() Returns instance(s) of Module_Kit objects
* @static object initiate() Creates/returns an instance of the particular Module_Kit object
*
* @method void activate() overrideable What to do when the module runs (ie extends initiate())
* @method bool add_action() Hooks a function on to a specific action if the module is enabled.
* @method bool add_filter() Hook a function or method to a specific filter action if the module is enabled.
* @method void add_options_fields( object ) overrideable Register the module's options page metabox
* @method void add_options_page( array ) Create/Get a module options page
* @method mixed get_option( string ) Get CMB2 options from Module's options page
* @method object get_parent() Retrieve the parent module object if one exists.
* @method object get_root() Retrieve the root module object.
* @method object get_template_loader() Get/create a template loader for the module
* @method string get_template_part( string, string, bool ) Retrieve a template part
* @method bool is_enabled() Check whether this module is active
* @method void load_submodules() Load any submodules in the mod directory once.
* @method string locate_template( mixed, bool, bool ) Retrieve the name of the highest priority template file that exists
* @method object parent() Alias for the get_parent method
*/
class MK_Module extends Module_Kit {
/**
* Module title
* @internal Overrideable
* Default: ''
* Defaults to the class name
* @var string
*/
protected $title = '';
/**
* Module naming prefix
* @internal Overrideable
* Default: 'mk'
* @var string
*/
protected $prefix = 'mk';
/**
* Whether the module is a Root Module or Submodule
* @internal Overrideable
* Default: null
* If true, module will initiate as a root module
* @var boolean
*/
private $is_root = null;
/**
* Run the module
*
* Add hooks, register an options page, load submodules
* @internal Overrideable
*/
protected function activate() {
Module_Kit::activate(); // default
# Register our options page
//$this->add_options_page();
# Setup up our hooks to always run
//add_action( 'init', [$this, 'init'] );
//add_filter( 'the_content', [$this, 'the_content'] );
# Set up our hooks to run when enabled
//$this->add_action( 'cmb2_admin_init', [$this, 'admin_init'] );
//$this->add_filter( 'the_content', [$this, 'the_content'] );
# Load our submodules
//$this->load_submodules();
# Set up our submodule-dependant hooks
// if ( static::class == self::class ) {
// # Setup up our mk_example related hooks
// if ( $submodule = self::get_instance('mk_example') ) {
// $submodule->add_filter( 'the_content', [$this, 'the_content'] );
// }
// }
}
/**
* Register a metabox for the Module's options page
* @internal Overrideable
* @see Module_Kit::add_options_page
* @uses CMB2
*/
public function add_options_fields( $cmb ) {
# Create a checkbox for each submodule
Module_Kit::add_options_fields($cmb); // default
# Set our CMB2 fields
// $cmb->add_field([
// 'name' => __( 'Test Text', 'myprefix' ),
// 'desc' => __( 'field description (optional)', 'myprefix' ),
// 'id' => 'test_text',
// 'type' => 'text',
// 'default' => 'Default Text',
// ]);
//
// $cmb->add_field([
// 'name' => __( 'Test Color Picker', 'myprefix' ),
// 'desc' => __( 'field description (optional)', 'myprefix' ),
// 'id' => 'test_colorpicker',
// 'type' => 'colorpicker',
// 'default' => '#bada55',
// ]);
}
} # End class.
MK_Module::initiate();
}