Groups - Version 1.13.0

Version Description

  • Added a filter on wp_count_posts.

=

Download this release

Release Info

Developer itthinx
Plugin Icon 128x128 Groups
Version 1.13.0
Comparing to
See all releases

Code changes from version 1.12.0 to 1.13.0

changelog.txt CHANGED
@@ -1,5 +1,8 @@
1
  == Groups changelog.txt ==
2
 
 
 
 
3
  = 1.12.0 =
4
  * Fixed an issue where resource paths were not correct with customized WP_CONTENT_DIR, WP_CONTENT_URL, WP_PLUGIN_DIR and WP_PLUGIN_URL.
5
 
@@ -361,4 +364,4 @@ Some installations wouldn't work correctly, showing no capabilities and making i
361
  * Improved admin CSS.
362
 
363
  = 1.0.0-beta-1 =
364
- * This is the first public beta release.
1
  == Groups changelog.txt ==
2
 
3
+ = 1.13.0 =
4
+ * Added a filter on wp_count_posts.
5
+
6
  = 1.12.0 =
7
  * Fixed an issue where resource paths were not correct with customized WP_CONTENT_DIR, WP_CONTENT_URL, WP_PLUGIN_DIR and WP_PLUGIN_URL.
8
 
364
  * Improved admin CSS.
365
 
366
  = 1.0.0-beta-1 =
367
+ * This is the first public beta release.
groups.php CHANGED
@@ -21,7 +21,7 @@
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.12.0
25
  * Author: itthinx
26
  * Author URI: http://www.itthinx.com
27
  * Donate-Link: http://www.itthinx.com
@@ -30,7 +30,7 @@
30
  if ( !defined( 'ABSPATH' ) ) {
31
  exit;
32
  }
33
- define( 'GROUPS_CORE_VERSION', '1.12.0' );
34
  define( 'GROUPS_FILE', __FILE__ );
35
  if ( !defined( 'GROUPS_CORE_DIR' ) ) {
36
  define( 'GROUPS_CORE_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
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.13.0
25
  * Author: itthinx
26
  * Author URI: http://www.itthinx.com
27
  * Donate-Link: http://www.itthinx.com
30
  if ( !defined( 'ABSPATH' ) ) {
31
  exit;
32
  }
33
+ define( 'GROUPS_CORE_VERSION', '1.13.0' );
34
  define( 'GROUPS_FILE', __FILE__ );
35
  if ( !defined( 'GROUPS_CORE_DIR' ) ) {
36
  define( 'GROUPS_CORE_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
lib/access/class-groups-post-access.php CHANGED
@@ -25,12 +25,6 @@ if ( !defined( 'ABSPATH' ) ) {
25
 
26
  /**
27
  * Post access restrictions.
28
- *
29
- * @todo when wp_count_posts() provides reasonable filters, use them so that
30
- * the post counts displayed on top are in line with the actual posts that
31
- * are displayed in the table; same for wp_count_attachments()
32
- * @see http://core.trac.wordpress.org/ticket/16603
33
- *
34
  */
35
  class Groups_Post_Access {
36
 
@@ -80,6 +74,9 @@ class Groups_Post_Access {
80
  // add_filter( "posts_join_paged", array( __CLASS__, "posts_join_paged" ), 1 );
81
  // add_filter( "posts_where_paged", array( __CLASS__, "posts_where_paged" ), 1 );
82
  add_action( 'groups_deleted_capability_capability', array( __CLASS__, 'groups_deleted_capability_capability' ) );
 
 
 
83
  }
84
 
85
  /**
@@ -436,5 +433,45 @@ class Groups_Post_Access {
436
  delete_metadata( 'post', null, self::POSTMETA_PREFIX . self::READ_POST_CAPABILITY, $capability, true );
437
  }
438
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
  }
440
  Groups_Post_Access::init();
25
 
26
  /**
27
  * Post access restrictions.
 
 
 
 
 
 
28
  */
29
  class Groups_Post_Access {
30
 
74
  // add_filter( "posts_join_paged", array( __CLASS__, "posts_join_paged" ), 1 );
75
  // add_filter( "posts_where_paged", array( __CLASS__, "posts_where_paged" ), 1 );
76
  add_action( 'groups_deleted_capability_capability', array( __CLASS__, 'groups_deleted_capability_capability' ) );
77
+ add_filter( 'wp_count_posts', array( __CLASS__, 'wp_count_posts' ), 10, 3 );
78
+ // @todo enable the filter and implement below if needed to correct attachment counts
79
+ // add_filter( 'wp_count_attachments', array( __CLASS__, 'wp_count_attachments' ), 10, 2 );
80
  }
81
 
82
  /**
433
  delete_metadata( 'post', null, self::POSTMETA_PREFIX . self::READ_POST_CAPABILITY, $capability, true );
434
  }
435
 
436
+ /**
437
+ * Hooked on wp_count_posts to correct the post counts.
438
+ *
439
+ * @param object $counts An object containing the current post_type's post counts by status.
440
+ * @param string $type the post type
441
+ * @param string $perm The permission to determine if the posts are 'readable' by the current user.
442
+ */
443
+ public static function wp_count_posts( $counts, $type, $perm ) {
444
+ foreach( $counts as $post_status => $count ) {
445
+ $query_args = array(
446
+ 'fields' => 'ids',
447
+ 'post_type' => $type,
448
+ 'post_status' => $post_status,
449
+ 'numberposts' => -1, // all
450
+ 'suppress_filters' => 0
451
+ );
452
+ if ( function_exists( 'wc_get_order_statuses' ) && ( $type == 'shop_order' ) ) {
453
+ $wc_order_statuses = array_keys( wc_get_order_statuses() );
454
+ if ( !in_array( $post_status, $wc_order_statuses ) ) {
455
+ $query_args['post_status'] = $wc_order_statuses;
456
+ }
457
+ }
458
+ $posts = get_posts( $query_args );
459
+ $count = count( $posts );
460
+ unset( $posts );
461
+ $counts->$post_status = $count;
462
+ }
463
+ return $counts;
464
+ }
465
+
466
+ /**
467
+ * Would be hooked on wp_count_attachments to correct the counts but it's not actually
468
+ * being used in the current media library.
469
+ *
470
+ * @param object $counts An object containing the attachment counts by mime type.
471
+ * @param string $mime_type The mime type pattern used to filter the attachments counted.
472
+ */
473
+ public static function wp_count_attachments( $counts, $mime_type ) {
474
+ return $counts;
475
+ }
476
  }
477
  Groups_Post_Access::init();
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: itthinx, proaktion
3
  Donate link: http://www.itthinx.com/plugins/groups
4
  Tags: access, access control, capability, capabilities, content, download, downloads, file, file access, files, group, groups, member, members, membership, memberships, paypal, permission, permissions, subscription, subscriptions, woocommerce
5
  Requires at least: 4.0
6
- Tested up to: 4.5.3
7
- Stable tag: 1.12.0
8
  License: GPLv3
9
 
10
  Groups is an efficient and powerful solution, providing group-based user membership management, group-based capabilities and content access control.
@@ -182,10 +182,10 @@ See also [Groups](http://www.itthinx.com/plugins/groups/)
182
 
183
  == Changelog ==
184
 
185
- = 1.12.0 =
186
- * Fixed an issue where resource paths were not correct with customized WP_CONTENT_DIR, WP_CONTENT_URL, WP_PLUGIN_DIR and WP_PLUGIN_URL.
187
 
188
  == Upgrade Notice ==
189
 
190
- = 1.12.0 =
191
- This release fixes issues with customized plugin and content directories.
3
  Donate link: http://www.itthinx.com/plugins/groups
4
  Tags: access, access control, capability, capabilities, content, download, downloads, file, file access, files, group, groups, member, members, membership, memberships, paypal, permission, permissions, subscription, subscriptions, woocommerce
5
  Requires at least: 4.0
6
+ Tested up to: 4.6
7
+ Stable tag: 1.13.0
8
  License: GPLv3
9
 
10
  Groups is an efficient and powerful solution, providing group-based user membership management, group-based capabilities and content access control.
182
 
183
  == Changelog ==
184
 
185
+ = 1.13.0 =
186
+ * Added a filter on wp_count_posts.
187
 
188
  == Upgrade Notice ==
189
 
190
+ = 1.13.0 =
191
+ This release corrects an issue related to the post counts displayed.