Skip to content

Commit

Permalink
Merge pull request #22 from alleyinteractive/feature/bp-group
Browse files Browse the repository at this point in the history
Support for BuddyPress Group Meta
  • Loading branch information
renatonascalves authored Sep 12, 2023
2 parents e606713 + 200b82d commit 3c3c06a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
4 changes: 4 additions & 0 deletions inc/class-wp-object.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public function render_meta_table( string $title = '', bool $hide_empty = false
$meta = (array) get_comment_meta( $this->object_id );
break;

case 'bp-group':
$meta = (array) groups_get_groupmeta( $this->object_id, '', false );
break;

case 'fm-term-meta':
if ( function_exists( 'fm_get_term_meta' ) ) {
$term = get_term( $this->object_id );
Expand Down
60 changes: 60 additions & 0 deletions inc/objects/class-bp-group.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Inspect groups.
*
* @package Meta_Inspector
*/

namespace Meta_Inspector;

/**
* Inspect meta for a BuddyPress group.
*/
class BP_Group extends WP_Object {
use Singleton;

/**
* Object type.
*
* @var string
*/
public $type = 'bp-group';

/**
* Initialize class.
*/
protected function __construct() {

// Bail if BuddyPress groups are not active.
if ( ! bp_is_active( 'groups' ) ) {
return;
}

add_action( 'bp_groups_admin_meta_boxes', [ $this, 'add_meta_boxes' ] );
}

/**
* Add meta boxes to the BuddyPress group edit screen.
*/
public function add_meta_boxes() {

// Store group ID.
$this->object_id = (int) sanitize_text_field( wp_unslash( $_GET['gid'] ?? 0 ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended

// Group meta.
add_meta_box(
'meta-inspector-bp-group-meta',
__( 'Meta', 'meta-inspector' ),
[ $this, 'render_meta' ],
get_current_screen()->id,
'normal'
);
}

/**
* Render a table of group meta.
*/
public function render_meta() {
$this->render_meta_table();
}
}
8 changes: 4 additions & 4 deletions inc/objects/class-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Meta_Inspector;

/**
* Inspect meta for users.
* Inspect meta for comments.
*/
class Comment extends WP_Object {
use Singleton;
Expand All @@ -28,7 +28,7 @@ protected function __construct() {
}

/**
* Add meta boxes to the post edit screen.
* Add meta boxes to the comment edit screen.
*/
public function add_meta_boxes() {

Expand All @@ -40,7 +40,7 @@ public function add_meta_boxes() {
// Store comment ID.
$this->object_id = get_comment_ID();

// Post meta.
// Comment meta.
add_meta_box(
'meta-inspector-comment-meta',
__( 'Comment Meta', 'meta-inspector' ),
Expand All @@ -51,7 +51,7 @@ public function add_meta_boxes() {
}

/**
* Render a table of post meta.
* Render a table of comment meta.
*/
public function render_meta() {
$this->render_meta_table();
Expand Down
8 changes: 7 additions & 1 deletion meta-inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Author URI: https://alley.com
* Text Domain: meta-inspector
* Domain Path: /languages
* Version: 1.1.0
* Version: 1.1.1
*
* @package Meta_Inspector
*/
Expand All @@ -26,6 +26,7 @@
require_once __DIR__ . '/inc/objects/class-user.php';
require_once __DIR__ . '/inc/objects/class-comment.php';
require_once __DIR__ . '/inc/objects/class-fm-term-meta.php';
require_once __DIR__ . '/inc/objects/class-bp-group.php';

// Initalize classes.
add_action(
Expand All @@ -46,5 +47,10 @@ function() {
Comment::instance();
// Legacy FM Term Meta Data support.
Fm_Term_Meta::instance();

// BuddyPress support.
if ( class_exists( 'BuddyPress' ) ) {
BP_Group::instance();
}
}
);

0 comments on commit 3c3c06a

Please sign in to comment.