my-calendar-db.php
3.06 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
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
// Define the table constants used in My Calendar in case anybody is still using them.
if ( is_multisite() && get_site_option( 'mc_multisite_show' ) == 1 ) {
define( 'MY_CALENDAR_TABLE', $wpdb->base_prefix . 'my_calendar' );
define( 'MY_CALENDAR_EVENTS_TABLE', $wpdb->base_prefix . 'my_calendar_events' );
define( 'MY_CALENDAR_CATEGORIES_TABLE', $wpdb->base_prefix . 'my_calendar_categories' );
define( 'MY_CALENDAR_LOCATIONS_TABLE', $wpdb->base_prefix . 'my_calendar_locations' );
} else {
define( 'MY_CALENDAR_TABLE', $wpdb->prefix . 'my_calendar' );
define( 'MY_CALENDAR_EVENTS_TABLE', $wpdb->prefix . 'my_calendar_events' );
define( 'MY_CALENDAR_CATEGORIES_TABLE', $wpdb->prefix . 'my_calendar_categories' );
define( 'MY_CALENDAR_LOCATIONS_TABLE', $wpdb->prefix . 'my_calendar_locations' );
}
if ( is_multisite() ) {
// Define the tables used in My Calendar
define( 'MY_CALENDAR_GLOBAL_TABLE', $wpdb->base_prefix . 'my_calendar' );
define( 'MY_CALENDAR_GLOBAL_EVENT_TABLE', $wpdb->base_prefix . 'my_calendar_events' );
define( 'MY_CALENDAR_GLOBAL_CATEGORIES_TABLE', $wpdb->base_prefix . 'my_calendar_categories' );
define( 'MY_CALENDAR_GLOBAL_LOCATIONS_TABLE', $wpdb->base_prefix . 'my_calendar_locations' );
}
/**
* Handlers for backwards compatibility
*/
function my_calendar_table( $site = false ) {
return my_calendar_select_table( 'my_calendar', $site );
}
function my_calendar_event_table( $site = false ) {
return my_calendar_select_table( 'my_calendar_events', $site );
}
function my_calendar_categories_table( $site = false ) {
return my_calendar_select_table( 'my_calendar_categories', $site );
}
function my_calendar_locations_table( $site = false ) {
return my_calendar_select_table( 'my_calendar_locations', $site );
}
/**
* Get table to query based on table data required & required site.
*
* @since 2.5.0
*
* @param string table name
* @param mixed 'global' to get global database; site ID to get that site's database; false for defaults according to settings.
*
* @return prefixed string table name
*/
function my_calendar_select_table( $table = 'my_calendar_events', $site = false ) {
global $wpdb;
$local = $wpdb->prefix . $table;
if ( is_multisite() ) {
$option = (int) get_site_option( 'mc_multisite' );
$choice = (int) get_option( 'mc_current_table' );
$show = (int) get_site_option( 'mc_multisite_show' ); // 1 == use global instead of local
if ( $site == 'global' ) {
return $wpdb->base_prefix . $table;
}
if ( $site != false && $site ) {
$site = absint( $site );
$wpdb->set_blog_id( $site );
}
$local = ( $show == 1 ) ? $wpdb->base_prefix . $table : $wpdb->prefix . $table;
$global = $wpdb->base_prefix . $table;
switch ( $option ) {
case 0:
return $local;
break;
case 1:
return $global;
break;
case 2:
return ( $choice == 1 ) ? $global : $local;
break;
default:
return $local;
}
} else {
return $local;
}
}