class-bootstrap.php
2.14 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
<?php
/**
* Everything should be init here
*
* @file
* @package Learndash_Certificate_Builer
*/
namespace LearnDash_Certificate_Builder;
use LearnDash_Certificate_Builder\Controller\Certificate_Builder;
/**
* Class Bootstrap
*
* @package LearnDash_Certificate_Builder
*/
class Bootstrap {
/**
* Contain the controller stack, so we don't need to init again
*
* @var array
*/
public $pool = array();
/**
* Initial function, everything should be start here
*/
public function init() {
if ( class_exists( '\SFWD_LMS' ) ) {
$this->pool[ Certificate_Builder::class ] = new Certificate_Builder();
} else {
// going to add an admin notice.
add_action( 'admin_notices', array( $this, 'requirement_notice' ) );
}
}
/**
* Register all the assets that will be use in this plugin, the controllers will enqueue it later
*/
public function register_assets() {
if ( ! class_exists( '\SFWD_LMS' ) ) {
return;
}
$this->get_controller( Certificate_Builder::class )->register_block();
}
/**
* If the learndash core doesn't activated, then we show this message.
*/
public function requirement_notice() {
?>
<div class="notice notice-warning is-dismissible">
<p>
<?php
// translators: Learndash website.
printf( esc_html__( 'LearnDash LMS - Certificate Builder Add-on requires the following plugin(s) to be active: %s', 'learndash-certificate-builder' ), '<a target="_blank" href="https://www.learndash.com/">LearnDash LMS</a>' );
?>
</p>
</div>
<?php
}
/**
* Load text domain.
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'learndash-certificate-builder', false, basename( dirname( __DIR__ ) ) . '/languages/' );
}
/**
* This function will check if a controller class has been initialed in the pool or not, if not, init and return
*
* @param string $name Should be the class name.
*
* @return false|mixed
*/
private function get_controller( $name ) {
if ( isset( $this->pool[ $name ] ) ) {
return $this->pool[ $name ];
}
if ( class_exists( $name ) ) {
$this->pool[ $name ] = new $name();
return $this->pool[ $name ];
}
return false;
}
}