-
Notifications
You must be signed in to change notification settings - Fork 11
/
batch-create.php
executable file
·170 lines (128 loc) · 5.09 KB
/
batch-create.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
170
<?php
/*
Plugin Name: Batch Create
Plugin URI: https://github.com/wpmudev/batch-create/
Description: Create hundred or thousands of blogs and users automatically by simply uploading a csv text file - subdomain and user creation automation has never been so easy.
Author: WPMU DEV
Text Domain: incsub_batch_create
Version: 1.5.2
Network: true
Author URI: http://premium.wpmudev.org/
WDP ID: 84
*/
/**
* The main class of the plugin
*/
class Incsub_Batch_Create {
// The version slug for the DB
public static $version_option_slug = 'incsub_batch_create_version';
// Admin pages. THey could be accesed from other points
// So they're statics
static $network_main_menu_page;
static $batch_creator;
public function __construct() {
$this->set_globals();
$this->includes();
add_action( 'init', array( &$this, 'maybe_upgrade' ) );
add_action( 'init', array( &$this, 'init_plugin' ) );
add_action( 'plugins_loaded', array( &$this, 'load_text_domain' ) );
register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
}
public function activate() {
$model = batch_create_get_model();
$model->create_schema();
update_site_option( self::$version_option_slug, INCSUB_BATCH_CREATE_VERSION );
}
public function deactivate() {
delete_site_option( self::$version_option_slug );
}
/**
* Set the plugin constants
*/
private function set_globals() {
//TODO: Change the constant names
// Basics
define( 'INCSUB_BATCH_CREATE_VERSION', '1.5.1' );
define( 'INCSUB_BATCH_CREATE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'INCSUB_BATCH_CREATE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'INCSUB_BATCH_CREATE_PLUGIN_FILE_DIR', plugin_dir_path( __FILE__ ) . 'batch-create.php' );
// Language domain
define( 'INCSUB_BATCH_CREATE_LANG_DOMAIN', 'incsub_batch_create' );
// URLs
define( 'INCSUB_BATCH_CREATE_ASSETS_URL', INCSUB_BATCH_CREATE_PLUGIN_URL . 'assets/' );
// Dirs
define( 'INCSUB_BATCH_CREATE_ADMIN_DIR', INCSUB_BATCH_CREATE_PLUGIN_DIR . 'admin/' );
define( 'INCSUB_BATCH_CREATE_MODEL_DIR', INCSUB_BATCH_CREATE_PLUGIN_DIR . 'model/' );
define( 'INCSUB_BATCH_CREATE_INCLUDES_DIR', INCSUB_BATCH_CREATE_PLUGIN_DIR . 'inc/' );
}
/**
* Include files needed
*/
private function includes() {
// Model
require_once( INCSUB_BATCH_CREATE_MODEL_DIR . 'model.php' );
// Libraries
require_once( INCSUB_BATCH_CREATE_INCLUDES_DIR . 'admin-page.php' );
require_once( INCSUB_BATCH_CREATE_INCLUDES_DIR . 'errors-handler.php' );
require_once( INCSUB_BATCH_CREATE_INCLUDES_DIR . 'helpers.php' );
require_once( INCSUB_BATCH_CREATE_INCLUDES_DIR . 'integration.php' );
// Admin Pages
require_once( INCSUB_BATCH_CREATE_ADMIN_DIR . 'pages/network-main-page.php' );
require_once( INCSUB_BATCH_CREATE_ADMIN_DIR . 'tables/queue-table.php' );
global $wpmudev_notices;
$wpmudev_notices[] = array( 'id'=> 84,'name'=> 'Batch Create', 'screens' => array( 'settings_page_batch-create-menu-network' ) );
include_once( 'externals/wpmudev-dash-notification.php' );
}
/**
* Upgrade the plugin when a new version is uploaded
*/
public function maybe_upgrade() {
$current_version = get_site_option( self::$version_option_slug );
if ( $current_version === INCSUB_BATCH_CREATE_VERSION )
return;
if ( $current_version === false ) {
$this->activate();
return;
}
// For the second version, we're just saving the version in DB
if ( version_compare( $current_version, '1.4', '<' ) ) {
require_once( INCSUB_BATCH_CREATE_INCLUDES_DIR . 'upgrade.php' );
batch_create_upgrade_14();
}
update_site_option( self::$version_option_slug, INCSUB_BATCH_CREATE_VERSION );
}
/**
* Load the plugin text domain and MO files
*
* These can be uploaded to the main WP Languages folder
* or the plugin one
*/
public function load_text_domain() {
load_plugin_textdomain( INCSUB_BATCH_CREATE_LANG_DOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Initialize the plugin
*/
public function init_plugin() {
global $wpdb;
require_once( INCSUB_BATCH_CREATE_INCLUDES_DIR . 'creator.php' );
$wpdb->batch_create_queuemeta = $wpdb->base_prefix . 'batch_create_queuemeta';
// A network menu
$args = array(
'parent' => 'settings.php',
'menu_title' => __( 'Batch Create', INCSUB_BATCH_CREATE_LANG_DOMAIN ),
'page_title' => __( 'Batch Create', INCSUB_BATCH_CREATE_LANG_DOMAIN ),
'network_menu' => true,
'screen_icon_slug' => 'batch-create',
'tabs' => array(
'upload' => __( 'Batch Create', INCSUB_BATCH_CREATE_LANG_DOMAIN ),
'queue' => __( 'Current queue', INCSUB_BATCH_CREATE_LANG_DOMAIN ),
'log-file' => __( 'Log File', INCSUB_BATCH_CREATE_LANG_DOMAIN )
)
);
self::$network_main_menu_page = new Batch_Create_Network_Main_Menu( 'batch-create-menu', 'manage_network', $args );
self::$batch_creator = new Incsub_Batch_Create_Creator();
}
}
new Incsub_Batch_Create();