-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.php
121 lines (96 loc) · 4.02 KB
/
index.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
<?php
/*
Plugin Name: BP Group Hierarchy
Plugin URI: http://www.generalthreat.com/projects/buddypress-group-hierarchy/
Description: Allows BuddyPress groups to belong to other groups
Version: 1.4.3
Revision Date: 04/09/2014
Requires at least: PHP 5, WP 3.2, BuddyPress 1.6
Tested up to: WP 3.8.2, BuddyPress 2.0-beta2
License: Example: GNU General Public License 2.0 (GPL) http://www.gnu.org/licenses/gpl.html
Author: David Dean
Author URI: http://www.generalthreat.com/
*/
define ( 'BP_GROUP_HIERARCHY_IS_INSTALLED', 1 );
define ( 'BP_GROUP_HIERARCHY_VERSION', '1.4.2' );
define ( 'BP_GROUP_HIERARCHY_DB_VERSION', 1 );
if( ! defined( 'BP_GROUP_HIERARCHY_SLUG' ) )
define ( 'BP_GROUP_HIERARCHY_SLUG', 'hierarchy' );
require ( dirname( __FILE__ ) . '/bp-group-hierarchy-filters.php' );
require ( dirname( __FILE__ ) . '/bp-group-hierarchy-actions.php' );
require ( dirname( __FILE__ ) . '/bp-group-hierarchy-widgets.php' );
/*************************************************************************
*********************SETUP AND INSTALLATION*******************************
*************************************************************************/
register_activation_hook( __FILE__, 'bp_group_hierarchy_install' );
/**
* Install and/or upgrade the database
*/
function bp_group_hierarchy_install() {
global $wpdb, $bp;
// Check whether BP is active and whether Groups component is loaded, and throw error if not
if( ! ( function_exists( 'buddypress' ) || is_a( $bp, 'BuddyPress' ) ) || ! bp_is_active( 'groups' ) ) {
_e( 'BuddyPress is not installed or the Groups component is not activated. Cannot continue install.', 'bp-group-hierarchy' );
exit;
}
if ( !empty($wpdb->charset) )
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
$sql[] = "CREATE TABLE {$bp->groups->table_name} (
parent_id BIGINT(20) NOT NULL DEFAULT 0,
KEY parent_id (parent_id),
) {$charset_collate};
";
if( ! get_site_option( 'bp-group-hierarchy-db-version' ) || get_site_option( 'bp-group-hierarchy-db-version' ) < BP_GROUP_HIERARCHY_DB_VERSION || ! bp_group_hierarchy_verify_install() ) {
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta($sql);
}
if( bp_group_hierarchy_verify_install( true ) ) {
update_site_option( 'bp-group-hierarchy-db-version', BP_GROUP_HIERARCHY_DB_VERSION );
} else {
die('Could not create the required column. Please enable debugging for more details.');
}
}
/**
* Try to DESCRIBE the groups table to see whether the column exists / was added
* @param bool $debug_column Whether to report that the required column wasn't found - this is normal pre-install
*/
function bp_group_hierarchy_verify_install( $debug_column = false ) {
global $wpdb, $bp;
/** Manually confirm that parent_id column exists */
$parent_id_exists = true;
$columns = $wpdb->get_results( 'DESCRIBE ' . $bp->groups->table_name );
if( $columns ) {
$parent_id_exists = false;
foreach( $columns as $column ) {
if( $column->Field == 'parent_id') {
$parent_id_exists = true;
break;
}
}
if( ! $parent_id_exists && $debug_column ) {
bp_group_hierarchy_debug( 'Required column was not found - last MySQL error was: ' . $wpdb->last_error );
return $parent_id_exists;
}
} else {
bp_group_hierarchy_debug( 'Could not DESCRIBE table - last MySQL error was: ' . $wpdb->last_error );
return false;
}
return $parent_id_exists;
}
/**
* Debugging function
*/
function bp_group_hierarchy_debug( $message ) {
if( ! defined( 'WP_DEBUG') || ! WP_DEBUG ) return;
if( is_array( $message ) || is_object( $message ) ) {
$message = print_r( $message, true );
}
if(defined( 'WP_DEBUG_LOG') && WP_DEBUG_LOG ) {
$GLOBALS['wp_log']['bp_group_hierarchy'][] = 'BP Group Hierarchy - ' . $message;
error_log('BP Group Hierarchy - ' . $message);
}
if( defined('WP_DEBUG_DISPLAY') && false !== WP_DEBUG_DISPLAY) {
echo '<div class="log">BP Group Hierarchy - ' . $message . "</div>\n";
}
}
?>