Skip to content

Commit

Permalink
Merge pull request #26 from alleyinteractive/feature/bp-activity
Browse files Browse the repository at this point in the history
Support for BuddyPress Activity Meta
  • Loading branch information
renatonascalves authored Feb 12, 2024
2 parents b001f0b + 9126cce commit d3365dc
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
4 changes: 4 additions & 0 deletions inc/class-wp-object.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public function render_meta_table( string $title = '', bool $hide_empty = false
$meta = (array) groups_get_groupmeta( $this->object_id, '', false );
break;

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

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

namespace Meta_Inspector;

/**
* Inspect meta for BuddyPress activities.
*/
class BP_Activity extends WP_Object {
use Singleton;

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

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

// Bail if the BuddyPress activity component is not active.
if ( ! bp_is_active( 'activity' ) ) {
return;
}

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

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

// Ensure the activity id is set.
if ( ! isset( $_GET['aid'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}

// Store activity id.
$this->object_id = (int) sanitize_text_field( wp_unslash( $_GET['aid'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended

// Get screen id.
$screen_id = get_current_screen()->id;

// Activity meta.
add_meta_box(
'meta-inspector-bp-activity-meta',
__( 'Meta', 'meta-inspector' ),
fn () => $this->render_meta_table(),
$screen_id,
'normal'
);
}
}
4 changes: 2 additions & 2 deletions inc/objects/class-bp-group.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Inspect groups.
* Inspect BuddyPress groups.
*
* @package Meta_Inspector
*/
Expand All @@ -25,7 +25,7 @@ class BP_Group extends WP_Object {
*/
protected function __construct() {

// Bail if BuddyPress groups are not active.
// Bail if the BuddyPress groups component is not active.
if ( ! bp_is_active( 'groups' ) ) {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions meta-inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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';
require_once __DIR__ . '/inc/objects/class-bp-activity.php';

// Initalize classes.
add_action(
Expand All @@ -44,12 +45,14 @@ function () {
Term::instance();
User::instance();
Comment::instance();

// Legacy FM Term Meta Data support.
Fm_Term_Meta::instance();

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

0 comments on commit d3365dc

Please sign in to comment.