forked from CFCommunity-net/buddypress-group-restrictions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buddypress-group-restrictions.php
121 lines (101 loc) · 3.69 KB
/
buddypress-group-restrictions.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: BuddyPress Group Restrictions
* Plugin URI: https://github.com/CFCommunity-net/buddypress-group-restrictions
* Description: Restrict group access according to member type.
* Version: 1.0.2
* Author: Henry Wright
* Contributors: imath, bowromir
* Author URI: http://about.me/henrywright
* Text Domain: buddypress-group-restrictions
* Domain Path: /languages/
*/
/**
* BuddyPress Group Restrictions
*
* @package BuddyPress Group Restrictions
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Main class
*
* Some general advices:
* - BuddyPress plugins should always load hooking to bp_include @see line 104
* - As this plugin is only playing with the groups component, do not include any
* file or run anything before we totally sure the component is active
* - Always test a plugin having in wp-config.php:
* - define( 'WP_DEBUG', true );
* - define( 'SCRIPT_DEBUG', true);
* - Minify the scripts / generate the pot at the very last moment.
* - Make sure to enqueue scripts only when needed. @see cfbgr_is_restriction_js()
*/
class CF_BG_Restrictions {
public static function start() {
$bp = buddypress();
// Plugin is requiring the groups & xProfile components
if ( ! bp_is_active( 'groups' ) || ! bp_is_active( 'xprofile' ) ) {
return;
}
// Extending the groups component
if ( empty( $bp->groups->restrictions ) ) {
$bp->groups->restrictions = new self;
}
return $bp->groups->restrictions;
}
public function __construct() {
// In case the class is called like new CF_BG_Restrictions()
if ( ! bp_is_active( 'groups' ) || ! bp_is_active( 'xprofile' ) ) {
return;
}
// Let's prevent some conflicts
if ( class_exists( 'BP_MT_Extended' ) ) {
return;
}
$this->setup_globals();
$this->includes();
$this->setup_hooks();
}
public function setup_globals() {
$this->version = '1.0.1';
$this->domain = 'buddypress-group-restrictions';
$this->file = __FILE__;
$this->basename = plugin_basename( $this->file );
$this->plugin_dir = plugin_dir_path( $this->file );
$this->plugin_url = plugin_dir_url ( $this->file );
$this->lang_dir = trailingslashit( $this->plugin_dir . 'languages' );
$this->includes_dir = trailingslashit( $this->plugin_dir . 'includes' );
$this->js_url = trailingslashit( $this->plugin_url . 'js' );
// Used to cache the member type field
$this->member_type_field = null;
}
public function includes() {
require( $this->includes_dir . 'functions.php' );
require( $this->includes_dir . 'field.php' );
require( $this->includes_dir . 'register.php' );
if ( is_admin() ) {
require( $this->includes_dir . 'migrate.php' );
}
}
// Translations for now...
public function setup_hooks() {
add_action( 'bp_init', array( $this, 'load_textdomain' ), 5 );
}
/**
* Loads the translation files
*/
public function load_textdomain() {
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), $this->domain );
$mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
// Setup paths to a buddypress-group-restrictions subfolder in WP LANG DIR
$mofile_global = WP_LANG_DIR . '/buddypress-group-restrictions/' . $mofile;
// Look in global /wp-content/languages/buddypress-group-restrictions folder
if ( ! load_textdomain( $this->domain, $mofile_global ) ) {
// Look in local /wp-content/plugins/buddypress-group-restrictions/languages/ folder
// or /wp-content/languages/plugins/
load_plugin_textdomain( $this->domain, false, basename( plugin_dir_path( $this->file ) ) . '/languages' );
}
}
}
add_action( 'bp_include', array( 'CF_BG_Restrictions', 'start' ) );