Skip to content

Commit

Permalink
Merge pull request #1557 from xwp/fix/1520-buddypress-action-links
Browse files Browse the repository at this point in the history
Fix BuddyPress Action links
  • Loading branch information
marcinkrzeminski authored Oct 8, 2024
2 parents 65f2763 + 452adb1 commit 9d2accb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
20.18.0
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"wp-coding-standards/wpcs": "^3.1",
"wp-phpunit/wp-phpunit": "^6.6",
"wpackagist-plugin/advanced-custom-fields": "6.3.4",
"wpackagist-plugin/buddypress": "14.0.0",
"wpackagist-plugin/classic-editor": "1.6.4",
"wpackagist-plugin/easy-digital-downloads": "3.3.1",
"wpackagist-plugin/jetpack": "13.6",
Expand Down
20 changes: 19 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions connectors/class-connector-buddypress.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ public function get_context_labels() {
* @return array Action links
*/
public function action_links( $links, $record ) {

// Check we have access to BuddyPress on this blog and that the user will have access to the links.
if ( ! $this->is_dependency_satisfied() || ! bp_current_user_can_moderate() ) {
return [];
}

// In the links, we also need to check the functions themselves as they're dependent on the BuddyPress module being enabled.
if ( in_array( $record->context, array( 'components' ), true ) ) {
$option_key = $record->get_meta( 'option_key', true );

Expand All @@ -181,7 +188,7 @@ public function action_links( $links, $record ) {
array(
'page' => 'bp-components',
),
admin_url( 'admin.php' )
get_admin_url( $record->blog_id, 'admin.php' )
);
} elseif ( 'bp-pages' === $option_key ) {
$page_id = $record->get_meta( 'page_id', true );
Expand All @@ -190,7 +197,7 @@ public function action_links( $links, $record ) {
array(
'page' => 'bp-page-settings',
),
admin_url( 'admin.php' )
get_admin_url( $record->blog_id, 'admin.php' )
);

if ( $page_id ) {
Expand All @@ -203,7 +210,7 @@ public function action_links( $links, $record ) {
array(
'page' => $record->get_meta( 'page', true ),
),
admin_url( 'admin.php' )
get_admin_url( $record->blog_id, 'admin.php' )
);
} elseif ( in_array( $record->context, array( 'groups' ), true ) && function_exists( 'groups_get_group' ) ) {
$group_id = $record->get_meta( 'id', true );
Expand All @@ -218,7 +225,7 @@ public function action_links( $links, $record ) {
$base_url = \bp_get_admin_url( 'admin.php?page=bp-groups&gid=' . $group_id );
$delete_url = wp_nonce_url( $base_url . '&action=delete', 'bp-groups-delete' );
$edit_url = $base_url . '&action=edit';
$visit_url = \bp_get_group_permalink( $group );
$visit_url = function_exists( 'bp_get_group_url' ) ? \bp_get_group_url( $group ) : \bp_get_group_permalink( $group );

$links[ esc_html__( 'Edit group', 'stream' ) ] = $edit_url;
$links[ esc_html__( 'View group', 'stream' ) ] = $visit_url;
Expand Down

0 comments on commit 9d2accb

Please sign in to comment.