Version Description
- Groups wouldn't activate due to a fatal error on WP <
Download this release
Release Info
Developer | itthinx |
Plugin | Groups |
Version | 1.0.0-beta-3 |
Comparing to | |
See all releases |
Code changes from version 1.0.0-beta-2 to 1.0.0-beta-3
- groups.php +5 -2
- lib/access/class-groups-access-meta-boxes.php +23 -8
- lib/access/{class-groups-shortcodes.php → class-groups-access-shortcodes.php} +4 -4
- lib/core/class-groups-user.php +1 -1
- lib/core/groups-tests.php +10 -5
- lib/core/wp-init.php +9 -1
- lib/views/class-groups-shortcodes.php +85 -0
- readme.txt +38 -1
groups.php
CHANGED
@@ -20,8 +20,8 @@
|
|
20 |
*
|
21 |
* Plugin Name: Groups
|
22 |
* Plugin URI: http://www.itthinx.com/plugins/groups
|
23 |
-
* Description: Groups provides
|
24 |
-
* Version: 1.0.0-beta-
|
25 |
* Author: itthinx (Karim Rahimpur)
|
26 |
* Author URI: http://www.itthinx.com
|
27 |
* Donate-Link: http://www.itthinx.com
|
@@ -44,6 +44,9 @@ if ( !defined( 'GROUPS_ADMIN_LIB' ) ) {
|
|
44 |
if ( !defined( 'GROUPS_AUTO_LIB' ) ) {
|
45 |
define( 'GROUPS_AUTO_LIB', GROUPS_CORE_DIR . '/lib/auto' );
|
46 |
}
|
|
|
|
|
|
|
47 |
if ( !defined( 'GROUPS_WP_LIB' ) ) {
|
48 |
define( 'GROUPS_WP_LIB', GROUPS_CORE_DIR . '/lib/wp' );
|
49 |
}
|
20 |
*
|
21 |
* Plugin Name: Groups
|
22 |
* Plugin URI: http://www.itthinx.com/plugins/groups
|
23 |
+
* Description: Groups provides group-based user membership management, group-based capabilities and content access control.
|
24 |
+
* Version: 1.0.0-beta-3
|
25 |
* Author: itthinx (Karim Rahimpur)
|
26 |
* Author URI: http://www.itthinx.com
|
27 |
* Donate-Link: http://www.itthinx.com
|
44 |
if ( !defined( 'GROUPS_AUTO_LIB' ) ) {
|
45 |
define( 'GROUPS_AUTO_LIB', GROUPS_CORE_DIR . '/lib/auto' );
|
46 |
}
|
47 |
+
if ( !defined( 'GROUPS_VIEWS_LIB' ) ) {
|
48 |
+
define( 'GROUPS_VIEWS_LIB', GROUPS_CORE_DIR . '/lib/views' );
|
49 |
+
}
|
50 |
if ( !defined( 'GROUPS_WP_LIB' ) ) {
|
51 |
define( 'GROUPS_WP_LIB', GROUPS_CORE_DIR . '/lib/wp' );
|
52 |
}
|
lib/access/class-groups-access-meta-boxes.php
CHANGED
@@ -42,14 +42,29 @@ class Groups_Access_Meta_Boxes {
|
|
42 |
* Triggered by init() to add capability meta box.
|
43 |
*/
|
44 |
public static function add_meta_boxes() {
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
54 |
|
55 |
/**
|
42 |
* Triggered by init() to add capability meta box.
|
43 |
*/
|
44 |
public static function add_meta_boxes() {
|
45 |
+
global $wp_version;
|
46 |
+
if ( $wp_version < 3.3 ) {
|
47 |
+
$post_types = get_post_types();
|
48 |
+
foreach ( $post_types as $post_type ) {
|
49 |
+
add_meta_box(
|
50 |
+
"groups-access",
|
51 |
+
__( "Access restrictions", GROUPS_PLUGIN_DOMAIN ),
|
52 |
+
array( __CLASS__, "capability" ),
|
53 |
+
$post_type,
|
54 |
+
"side",
|
55 |
+
"high"
|
56 |
+
);
|
57 |
+
}
|
58 |
+
} else {
|
59 |
+
add_meta_box(
|
60 |
+
"groups-access",
|
61 |
+
__( "Access restrictions", GROUPS_PLUGIN_DOMAIN ),
|
62 |
+
array( __CLASS__, "capability" ),
|
63 |
+
null,
|
64 |
+
"side",
|
65 |
+
"high"
|
66 |
+
);
|
67 |
+
}
|
68 |
}
|
69 |
|
70 |
/**
|
lib/access/{class-groups-shortcodes.php → class-groups-access-shortcodes.php}
RENAMED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* class-groups-
|
4 |
*
|
5 |
* Copyright (c) "kento" Karim Rahimpur www.itthinx.com
|
6 |
*
|
@@ -18,10 +18,10 @@
|
|
18 |
* @package groups
|
19 |
* @since groups 1.0.0
|
20 |
*/
|
21 |
-
class
|
22 |
|
23 |
/**
|
24 |
-
* Defines shortcodes.
|
25 |
*/
|
26 |
public static function init() {
|
27 |
|
@@ -144,4 +144,4 @@ class Groups_Shortcodes {
|
|
144 |
return $output;
|
145 |
}
|
146 |
}
|
147 |
-
|
1 |
<?php
|
2 |
/**
|
3 |
+
* class-groups-access-shortcodes.php
|
4 |
*
|
5 |
* Copyright (c) "kento" Karim Rahimpur www.itthinx.com
|
6 |
*
|
18 |
* @package groups
|
19 |
* @since groups 1.0.0
|
20 |
*/
|
21 |
+
class Groups_Access_Shortcodes {
|
22 |
|
23 |
/**
|
24 |
+
* Defines access shortcodes.
|
25 |
*/
|
26 |
public static function init() {
|
27 |
|
144 |
return $output;
|
145 |
}
|
146 |
}
|
147 |
+
Groups_Access_Shortcodes::init();
|
lib/core/class-groups-user.php
CHANGED
@@ -105,7 +105,7 @@ class Groups_User implements I_Capable {
|
|
105 |
|
106 |
// if administrators can override access, let them
|
107 |
if ( get_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE_DEFAULT ) ) {
|
108 |
-
if ( user_can( $this->user, 'administrator' ) ) {
|
109 |
return true;
|
110 |
}
|
111 |
}
|
105 |
|
106 |
// if administrators can override access, let them
|
107 |
if ( get_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE_DEFAULT ) ) {
|
108 |
+
if ( user_can( $this->user->ID, 'administrator' ) ) { // just using $this->user would raise a warning on 3.2.1
|
109 |
return true;
|
110 |
}
|
111 |
}
|
lib/core/groups-tests.php
CHANGED
@@ -93,25 +93,30 @@ if ( defined( 'ABSPATH' ) ) {
|
|
93 |
// *** users ***
|
94 |
|
95 |
// create test users
|
96 |
-
$
|
|
|
97 |
assert( '$foo_user_id instanceof WP_Error === false');
|
98 |
|
99 |
-
$
|
|
|
100 |
assert( '$bar_user_id instanceof WP_Error === false');
|
101 |
|
102 |
// this user is used to test the automatic resolution of its relationship
|
103 |
// with the banana group when the group is deleted
|
104 |
// it's also used to test automatic resolution of its "clap" capability
|
105 |
// after that capability has been deleted
|
106 |
-
$
|
|
|
107 |
assert( '$baz_user_id instanceof WP_Error === false');
|
108 |
|
109 |
// this user is deleted, the group relation must be deleted automatically
|
110 |
-
$
|
|
|
111 |
assert( '$dol_user_id instanceof WP_Error === false');
|
112 |
|
113 |
// this user is a simple editor, used to test WordPress capabilities
|
114 |
-
$
|
|
|
115 |
assert( '$editor_user_id instanceof WP_Error === false');
|
116 |
if ( !( $editor_user_id instanceof WP_Error ) ) {
|
117 |
$editor_user = new WP_User( $editor_user_id );
|
93 |
// *** users ***
|
94 |
|
95 |
// create test users
|
96 |
+
$fooname = 'foo' . rand(0, 100);
|
97 |
+
$foo_user_id = wp_create_user( $fooname, 'foo', $fooname . '@example.com' );
|
98 |
assert( '$foo_user_id instanceof WP_Error === false');
|
99 |
|
100 |
+
$barname = 'bar' . rand(0, 100);
|
101 |
+
$bar_user_id = wp_create_user( $barname, 'bar', $barname . '@example.com' );
|
102 |
assert( '$bar_user_id instanceof WP_Error === false');
|
103 |
|
104 |
// this user is used to test the automatic resolution of its relationship
|
105 |
// with the banana group when the group is deleted
|
106 |
// it's also used to test automatic resolution of its "clap" capability
|
107 |
// after that capability has been deleted
|
108 |
+
$bazname = 'baz' . rand(0, 100);
|
109 |
+
$baz_user_id = wp_create_user( $bazname, 'baz', $bazname . '@example.com' );
|
110 |
assert( '$baz_user_id instanceof WP_Error === false');
|
111 |
|
112 |
// this user is deleted, the group relation must be deleted automatically
|
113 |
+
$dolname = 'dol' . rand(0, 100);
|
114 |
+
$dol_user_id = wp_create_user( $dolname, 'dol', $dolname . ' @example.com' );
|
115 |
assert( '$dol_user_id instanceof WP_Error === false');
|
116 |
|
117 |
// this user is a simple editor, used to test WordPress capabilities
|
118 |
+
$editorname = 'rotide' . rand(0, 100);
|
119 |
+
$editor_user_id = wp_create_user( $editorname, 'rotide', $editorname . '@example.com' );
|
120 |
assert( '$editor_user_id instanceof WP_Error === false');
|
121 |
if ( !( $editor_user_id instanceof WP_Error ) ) {
|
122 |
$editor_user = new WP_User( $editor_user_id );
|
lib/core/wp-init.php
CHANGED
@@ -29,6 +29,13 @@ if ( !isset( $groups_version ) ) {
|
|
29 |
$groups_version = GROUPS_CORE_VERSION;
|
30 |
}
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
/**
|
33 |
* Load core :
|
34 |
*/
|
@@ -70,7 +77,8 @@ require_once( GROUPS_ACCESS_LIB . '/class-groups-post-access.php' );
|
|
70 |
if ( is_admin() ) {
|
71 |
require_once( GROUPS_ACCESS_LIB . '/class-groups-access-meta-boxes.php' );
|
72 |
}
|
73 |
-
require_once( GROUPS_ACCESS_LIB . '/class-groups-shortcodes.php' );
|
|
|
74 |
|
75 |
/**
|
76 |
* Load wp :
|
29 |
$groups_version = GROUPS_CORE_VERSION;
|
30 |
}
|
31 |
|
32 |
+
// <= 3.2.1
|
33 |
+
if ( !function_exists( 'is_user_member_of_blog' ) ) {
|
34 |
+
function is_user_member_of_blog( $user_id, $blog_id = 0 ) {
|
35 |
+
return false !== get_user_by( "id", $user_id );
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
/**
|
40 |
* Load core :
|
41 |
*/
|
77 |
if ( is_admin() ) {
|
78 |
require_once( GROUPS_ACCESS_LIB . '/class-groups-access-meta-boxes.php' );
|
79 |
}
|
80 |
+
require_once( GROUPS_ACCESS_LIB . '/class-groups-access-shortcodes.php' );
|
81 |
+
require_once( GROUPS_VIEWS_LIB . '/class-groups-shortcodes.php' );
|
82 |
|
83 |
/**
|
84 |
* Load wp :
|
lib/views/class-groups-shortcodes.php
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* class-groups-shortcodes.php
|
4 |
+
*
|
5 |
+
* Copyright (c) "kento" Karim Rahimpur www.itthinx.com
|
6 |
+
*
|
7 |
+
* This code is released under the GNU General Public License.
|
8 |
+
* See COPYRIGHT.txt and LICENSE.txt.
|
9 |
+
*
|
10 |
+
* This code is distributed in the hope that it will be useful,
|
11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
* GNU General Public License for more details.
|
14 |
+
*
|
15 |
+
* This header and all notices must be kept intact.
|
16 |
+
*
|
17 |
+
* @author Karim Rahimpur
|
18 |
+
* @package groups
|
19 |
+
* @since groups 1.0.0
|
20 |
+
*/
|
21 |
+
class Groups_Shortcodes {
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Adds shortcodes.
|
25 |
+
*/
|
26 |
+
public static function init() {
|
27 |
+
// group info
|
28 |
+
add_shortcode( 'groups_group_info', array( __CLASS__, 'groups_group_info' ) );
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Renders information about a group.
|
33 |
+
* Attributes:
|
34 |
+
* - "group" : group name or id
|
35 |
+
* - "show" : what to show, can be "name", "description", "count"
|
36 |
+
*
|
37 |
+
* @param array $atts attributes
|
38 |
+
* @param string $content content to render
|
39 |
+
* @return rendered information
|
40 |
+
*/
|
41 |
+
public static function groups_group_info( $atts, $content = null ) {
|
42 |
+
global $wpdb;
|
43 |
+
$output = "";
|
44 |
+
$options = shortcode_atts(
|
45 |
+
array(
|
46 |
+
'group' => '',
|
47 |
+
'show' => '',
|
48 |
+
'format' => '',
|
49 |
+
'single' => '1',
|
50 |
+
'plural' => '%d'
|
51 |
+
),
|
52 |
+
$atts
|
53 |
+
);
|
54 |
+
$group = trim( $options['group'] );
|
55 |
+
$current_group = Groups_Group::read( $group );
|
56 |
+
if ( !$current_group ) {
|
57 |
+
$current_group = Groups_Group::read_by_name( $group );
|
58 |
+
}
|
59 |
+
if ( $current_group ) {
|
60 |
+
switch( $options['show'] ) {
|
61 |
+
case 'name' :
|
62 |
+
$output .= wp_filter_nohtml_kses( $current_group->name );
|
63 |
+
break;
|
64 |
+
case 'description' :
|
65 |
+
$output .= wp_filter_nohtml_kses( $current_group->description );
|
66 |
+
break;
|
67 |
+
case 'count' :
|
68 |
+
$user_group_table = _groups_get_tablename( "user_group" );
|
69 |
+
$count = $wpdb->get_var( $wpdb->prepare(
|
70 |
+
"SELECT COUNT(*) FROM $user_group_table WHERE group_id = %d",
|
71 |
+
Groups_Utility::id( $current_group->group_id )
|
72 |
+
) );
|
73 |
+
if ( $count === null ) {
|
74 |
+
$count = 0;
|
75 |
+
} else {
|
76 |
+
$count = intval( $count );
|
77 |
+
}
|
78 |
+
$output .= _n( $options['single'], sprintf( $options['plural'], $count ), $count, GROUPS_PLUGIN_DOMAIN );
|
79 |
+
break;
|
80 |
+
}
|
81 |
+
}
|
82 |
+
return $output;
|
83 |
+
}
|
84 |
+
}
|
85 |
+
Groups_Shortcodes::init();
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.itthinx.com/plugins/groups
|
|
4 |
Tags: access, access control, capability, capabilities, content, group, groups, member, members, membership, permission, permissions
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.3.1
|
7 |
-
Stable tag: 1.0.0-beta-
|
8 |
|
9 |
Groups provides group-based user membership management, group-based capabilities and content access control.
|
10 |
|
@@ -170,6 +170,36 @@ For each role these permissions can be set:
|
|
170 |
A convenient option is provided to delete all data that has been stored by the Groups plugin.
|
171 |
This option is useful if you just need to start from fresh after you have been testing the plugin.
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
== Installation ==
|
174 |
|
175 |
1. Upload or extract the `groups` folder to your site's `/wp-content/plugins/` directory. You can also use the *Add new* option found in the *Plugins* menu in WordPress.
|
@@ -202,6 +232,10 @@ See also [Groups](http://www.itthinx.com/plugins/groups/)
|
|
202 |
|
203 |
== Changelog ==
|
204 |
|
|
|
|
|
|
|
|
|
205 |
= 1.0.0-beta-2 =
|
206 |
* Increased length of capability.capability, capability.class, capability.object columns to support long capabilities.
|
207 |
* Improved admin CSS.
|
@@ -211,6 +245,9 @@ See also [Groups](http://www.itthinx.com/plugins/groups/)
|
|
211 |
|
212 |
== Upgrade Notice ==
|
213 |
|
|
|
|
|
|
|
214 |
= 1.0.0-beta-2 =
|
215 |
* Increased length of capability.capability, capability.class and capability.object columns from to 255 => you need to update your DB manually if you want that updated.
|
216 |
* Improved some admin CSS.
|
4 |
Tags: access, access control, capability, capabilities, content, group, groups, member, members, membership, permission, permissions
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.3.1
|
7 |
+
Stable tag: 1.0.0-beta-3
|
8 |
|
9 |
Groups provides group-based user membership management, group-based capabilities and content access control.
|
10 |
|
170 |
A convenient option is provided to delete all data that has been stored by the Groups plugin.
|
171 |
This option is useful if you just need to start from fresh after you have been testing the plugin.
|
172 |
|
173 |
+
### Shortcodes ###
|
174 |
+
|
175 |
+
#### Limit content visibility ####
|
176 |
+
|
177 |
+
These shortcodes are used to limit the visibility of the content they enclose:
|
178 |
+
|
179 |
+
- [groups_member]
|
180 |
+
- [groups_non_member]
|
181 |
+
- [groups_can]
|
182 |
+
- [groups_can_not]
|
183 |
+
|
184 |
+
See above for examples and descriptions.
|
185 |
+
|
186 |
+
#### Show group information ####
|
187 |
+
|
188 |
+
- [groups_group_info]
|
189 |
+
|
190 |
+
This shortcode takes the following attributes to show information about a group:
|
191 |
+
|
192 |
+
- _group_ : (required) the group ID or name
|
193 |
+
- _show_ : (required) what to show, accepted values are: _name_, _description_, _count_
|
194 |
+
- _single_ : (optional) used when show="count" and there is 1 member in the group
|
195 |
+
- _plural_ : (optional) used when show="count" and there is more than 1 member in the group, must contain %d to show the number of members
|
196 |
+
|
197 |
+
Examples:
|
198 |
+
|
199 |
+
* [groups_group_info group="Registered" show="count"]
|
200 |
+
|
201 |
+
* There [groups_group_info group="1" show="count" single="is one member" plural="are %d members"] in the [groups_group_info group="1" show="name"] group.
|
202 |
+
|
203 |
== Installation ==
|
204 |
|
205 |
1. Upload or extract the `groups` folder to your site's `/wp-content/plugins/` directory. You can also use the *Add new* option found in the *Plugins* menu in WordPress.
|
232 |
|
233 |
== Changelog ==
|
234 |
|
235 |
+
= 1.0.0-beta-3 =
|
236 |
+
* Groups wouldn't activate due to a fatal error on WP <= 3.2.1 : is_user_member_of_blog() is defined in ms-functions.php
|
237 |
+
* Added [groups_group_info] shortcode
|
238 |
+
|
239 |
= 1.0.0-beta-2 =
|
240 |
* Increased length of capability.capability, capability.class, capability.object columns to support long capabilities.
|
241 |
* Improved admin CSS.
|
245 |
|
246 |
== Upgrade Notice ==
|
247 |
|
248 |
+
= 1.0.0-beta-3 =
|
249 |
+
* New shortcode to show group info & WP <= 3.2.1 compatibility fix.
|
250 |
+
|
251 |
= 1.0.0-beta-2 =
|
252 |
* Increased length of capability.capability, capability.class and capability.object columns from to 255 => you need to update your DB manually if you want that updated.
|
253 |
* Improved some admin CSS.
|