-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulk-page-maker-light.php
169 lines (145 loc) · 4.12 KB
/
bulk-page-maker-light.php
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/*
Plugin Name: Bulk Page Maker Light
Description: A Light plugin to generate bulk WordPress Pages or Posts
Version: 1.4.0
Author: Sapayth H.
Author URI: http://sapayth.com
License: GPLv2 or later
Requires at least: 5.4
Requires PHP: 5.6
Text Domain: sh-bpm-light
*/
/*
* **********************************************************************
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* **********************************************************************
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require_once __DIR__ . '/vendor/autoload.php';
}
/**
* The main plugin class
*/
final class Bulk_Page_Maker {
/**
* Plugin version
*
* @var string
*/
const VERSION = '1.4.0';
// the instance to hold the class object
protected static $instance = null;
// Holds various class instances
private $container = [];
/*
* class constructor
*/
private function __construct() {
$this->define_constants();
register_activation_hook( __FILE__, [ $this, 'activate' ] );
register_deactivation_hook( __FILE__, [ $this, 'deactivate' ] );
add_action( 'init', [ $this, 'init_plugin' ] );
}
/*
* Initializes a singleton instance
*/
public static function init() {
if ( ! is_null( self::$instance ) ) {
return self::$instance;
}
self::$instance = new self();
return self::$instance;
}
/**
* Define all plugin constants
*
* @return void
*/
public function define_constants() {
$this->define( 'BPM_VERSION', self::VERSION );
$this->define( 'BPM_FILE', __FILE__ );
$this->define( 'BPM_PATH', __DIR__ );
$this->define( 'BPM_ADMIN_PATH', BPM_PATH . '/includes/Admin' );
$this->define( 'BPM_URL', plugins_url( '', BPM_FILE ) );
$this->define( 'BPM_ASSETS', BPM_URL . '/assets' );
}
/**
* Define constant if not already set.
*
* @param string $const Constant name.
* @param mixed $value Constant value.
*/
private function define( $const, $value ) {
if ( ! defined( $const ) ) {
define( $const, $value );
}
}
/**
* Initialize the plugin
*
* @return void
*/
public function init_plugin() {
$this->container['assets'] = new Bulk\Page\Maker\Assets();
if ( is_admin() ) {
$this->container['admin'] = new Bulk\Page\Maker\Admin();
}
}
/**
* Do stuff upon plugin activation
*/
public function activate() {
$installer = new Bulk\Page\Maker\Installer();
$installer->run();
}
/**
* Do stuff upon plugin deactivation
*/
public function deactivate() {
$transient_posts = 'bpmaker_all_pages';
$transient_count = 'bpmaker_pages_count';
// delete releated transient
if ( false !== get_transient( $transient_count ) ) {
delete_transient( $transient_count );
}
// delete releated transient
if ( false !== get_transient( $transient_posts ) ) {
delete_transient( $transient_posts );
}
}
/**
* Magic getter to bypass referencing objects
*
* @since 1.4.0
*
* @param string $prop
*
* @return Class Instance
*/
public function __get( $prop ) {
if ( array_key_exists( $prop, $this->container ) ) {
return $this->container[ $prop ];
}
}
}
/**
* Initialize the main plugin
*/
if ( ! function_exists( 'bpmaker_make_page' ) ) {
function bpmaker_make_page() {
return Bulk_Page_Maker::init();
}
}
// start the plugin
bpmaker_make_page();