-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a bp_read
cap to handle community visibility
#25
Conversation
1. Use a theme or template pack template to display the community visibility message. 2. In case the theme or the template pack does not include the new template, fallback to @dcavins way of redirecting to the login page. 3. Catch all BP URI globals and send it to the capability check so that plugins can eventually leave not logged in visitors to access their content according to the URL being requested. 4. Improve various `bp_core_no_access...` functions to allow login page error customization for the no community access context.
c7b432a
to
2511c55
Compare
* Check the `$args` filter's parameter (4th one) to find the requested URI globals. | ||
* eg: `$args['current_component']` for the component. | ||
*/ | ||
if ( ! bp_current_user_can( 'bp_read', $bp_uri_globals ) && ! in_array( $bp_uri_globals['current_component'], array( 'register', 'activate' ), true ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example to let any user access to the members directory:
function leave_members_component_visible( $caps, $cap, $user_id, $args ) {
$r = reset( $args );
if ( 'bp_read' === $cap && isset( $r['current_component'] ) && 'members' === $r['current_component'] ) {
$caps = array( 'exist' );
}
return $caps;
}
add_filter( 'bp_map_meta_caps', 'leave_members_component_visible', 10, 4 );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few suggestions!
|
||
// A template part was found load it. | ||
} else { | ||
add_filter( 'bp_replace_the_content', array( $this, 'gate_content' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add phpdoc?
* Filter the_content with the community gate template part. | ||
* | ||
* @since 11.0.0 | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing @return
array( | ||
'a' => array( | ||
'href' => true, | ||
), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might prove problematic. Imagine if I hook here and pass something like this: <a><span></span></a>
...
* | ||
* @param string $value The current community area visibility. | ||
*/ | ||
return apply_filters( 'bp_get_community_visibility', bp_get_option( '_bp_community_visibility', $default ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest passing the $default
as a second parameter.
* @return string The community gate slug. | ||
*/ | ||
function bp_core_get_community_gate_slug() { | ||
$slug = apply_filters( 'bp_core_community_gate_slug', __( 'community-gate', 'buddypress' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing phpdoc?
A new & improved way of dealing with this visibility feature will be soon worked on. |
The main idea is to unset the
buddypress()->pages
when the user hasn't the WP Cap mapped to a newbp_read
one. As a result BP Globals likecurrent_component
,current_action
andaction_variables
are not set and we end up into a! is_buddypress()
area for not logged in members when the community visibility option is set tomembers
. Activity RSS feed are then not set. I believe if we use this scenario, we'll need to edit the BP Rest API endpoints to use thebp_current_user_can( 'bp_read' )
into the permissions_check methods.A benefit of this is the site admin can easily customize the default content displayed to not logged in members using the Block Editor for the corresponding BP Pages.
Trac ticket: https://buddypress.trac.wordpress.org/ticket/8734
This Pull Request is for code review only. Please keep all other discussion in the BuddyPress Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the WordPress Core Handbook for more details.