forked from wp-plugins/horizontal-meta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.php
188 lines (125 loc) · 4.67 KB
/
loader.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/*
Plugin Name: Horizontal Meta
Plugin URI: http://wordpress.org/plugins/horizontal-meta/
Description: Alters the way WordPress handles meta data to allow for query-able data-typed fields and performance.
Version: 2.3.1
Author: Nathan Franklin
Author URI: http://www.nathanfranklin.com.au/
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Network: true
*/
// General setup... getting plugin ready to load.
defined( 'ABSPATH' ) OR exit;
// include system file for loading plugin.
include dirname(__FILE__) . '/system/plugin_init.php';
// init functions
if(file_exists(dirname(__FILE__) . '/functions.php')) {
require_once dirname(__FILE__) . '/functions.php';
}
// Load languages
load_plugin_textdomain('horizontal-meta', false, basename(dirname(__FILE__)) . '/languages');
hmeta_load_init(basename(dirname(__FILE__)));
//add_action('plugins_loaded', $init_func, 0);
// Load moduled functions.
if(file_exists(dirname(__FILE__) . "/functions/") & is_dir(dirname(__FILE__) . "/functions/")) {
$function_files = scandir(dirname(__FILE__) . "/functions/");
foreach($function_files as $function_file) {
if(substr($function_file, -4) == ".php") {
require_once dirname(__FILE__) . "/functions/" . $function_file;
}
}
}
register_activation_hook(__FILE__, 'horizontal_meta_activate');
register_deactivation_hook(__FILE__, 'horizontal_meta_deactivate');
/**
* Ensure the we create the additional meta_tables needed for the new blog.
*/
function hm_horzm_new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta ) {
global $wpdb;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
require_once "system/loader_base.php";
require_once "system/library_base.php";
require_once "libraries/hm_mappings_library.php";
require_once "libraries/hm_log_library.php";
require_once plugin_dir_path( __FILE__ ) . "/setup.php";
$current_blog = get_current_blog_id();
if($current_blog != $blog_id)
switch_to_blog($blog_id);
// create our meta tables
create_hm_meta_tables($wpdb->prefix, $blog_id);
if($current_blog != $blog_id)
restore_current_blog();
}
add_action( 'wpmu_new_blog', 'hm_horzm_new_blog', 10, 100);
function horizontal_meta_deactivate() {
global $wpdb;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
require_once "system/loader_base.php";
require_once "system/library_base.php";
require_once "libraries/hm_mappings_library.php";
require_once "libraries/hm_log_library.php";
require_once plugin_dir_path( __FILE__ ) . "/setup.php";
$lib = new hm_mappings_library();
if(!current_user_can( 'activate_plugins')) {
return;
}
$plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
check_admin_referer( "deactivate-plugin_{$plugin}" );
// need to ensure we have enough time to run
set_time_limit(1800);
if (function_exists('is_multisite') && is_multisite()) {
$current_blog = get_current_blog_id();
$blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
foreach ($blogids as $blog_id) {
if($current_blog != $blog_id)
switch_to_blog($blog_id);
// restore the meta data
hm_clear_mappings($blog_id, $lib);
if($current_blog != $blog_id)
restore_current_blog();
}
} else {
// restore the meta data
hm_clear_mappings(1, $lib);
}
}
/**
* @param bool $new_blog_id This will be passed when a new blog has just been created. This will force an activation for this blog.
*/
function horizontal_meta_activate() {
global $wpdb;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
require_once "system/loader_base.php";
require_once "system/library_base.php";
require_once "libraries/hm_mappings_library.php";
require_once "libraries/hm_log_library.php";
require_once plugin_dir_path( __FILE__ ) . "/setup.php";
$lib = new hm_mappings_library();
if(!current_user_can( 'activate_plugins')) {
return;
}
$plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
check_admin_referer( "activate-plugin_{$plugin}" );
// need to ensure we have enough time to run
set_time_limit(1800);
if (function_exists('is_multisite') && is_multisite()) {
$current_blog = get_current_blog_id();
$blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
foreach ($blogids as $blog_id) {
if($current_blog != $blog_id)
switch_to_blog($blog_id);
// create our meta tables
create_hm_meta_tables($wpdb->prefix, $blog_id);
// restore the data that was originally in the table from the meta tables
hm_reinstate_data($blog_id, $lib);
if($current_blog != $blog_id)
restore_current_blog();
}
} else {
create_hm_meta_tables($wpdb->prefix);
// restore the data that was originally in the table from the meta tables
hm_reinstate_data(1, $lib);
}
}