Skip to content

Conversation

@vaurdan
Copy link
Contributor

@vaurdan vaurdan commented Jul 23, 2024

Description

We got reports that VIP support users were unable to access PCH features after the introduction of PCH permissions.

This PR gives a pathway to fix this. It introduces a new filter, wp_parsely_current_user_can_use_pch_feature, to the current_user_can_use_pch_feature function in the class-permissions.php file. This filter allows developers to override the default permissions check for specific Content Helper features.

By using the filter, we'll now be able to grant PCH feature access to VIP support users.

The filter provides several parameters:

  • $current_user_can_use_pch_feature (bool) to indicate whether the current user can use the feature
  • $feature_name (string) for the feature's name
  • $current_user (\WP_User) representing the current user object
  • $post_id (int|false) for the post ID if the check is for a specific post. If the filter returns true, the function immediately grants permission, bypassing the default role-based check.

This change allows more flexibility for customizing each feature permission based on specific requirements. Here's an example on how you could use to allow a specific role to have access to the Smart Linking feature.

function allow_example_role_to_use_smart_linking( $current_user_can_use_pch_feature, $feature_name, $current_user, $post_id ) {
    // Check if the feature is 'smart-linking'
    if ( $feature_name === 'smart-linking' ) {
        // Check if the current user has the 'example-role' role
        if ( in_array( 'example-role', $current_user->roles, true ) ) {
            return true;
        }
    }
    
    // Return the original permission check result if conditions are not met
    return $current_user_can_use_pch_feature;
}
add_filter( 'wp_parsely_current_user_can_use_pch_feature', 'allow_example_role_to_use_smart_linking', 10, 4 );

Motivation and context

Improve the flexibility and extensibility of PCH access control.

How has this been tested?

Tested locally.

@vaurdan vaurdan added the Changelog: Added PR to be added under the changelog's "Added" section label Jul 23, 2024
@vaurdan vaurdan added this to the 3.16.2 milestone Jul 23, 2024
@vaurdan vaurdan self-assigned this Jul 23, 2024
@vaurdan vaurdan requested a review from a team as a code owner July 23, 2024 10:23
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 23, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Base branches to auto review (4)
  • develop
  • add/.*
  • fix/.*
  • update/.*

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Co-authored-by: Alex Cicovic <23142906+acicovic@users.noreply.github.com>
@vaurdan vaurdan merged commit 2499a22 into prepare/3.16.2 Jul 24, 2024
@vaurdan vaurdan deleted the update/add-filter-pch-permission-check branch July 24, 2024 11:06
@acicovic acicovic changed the title Permissions: Add filter to override default permissions for PCH features Permissions: Allow overriding of PCH feature permissions Jul 30, 2024
@acicovic acicovic added Changelog: Fixed PR to be added under the changelog's "Fixed" section and removed Changelog: Added PR to be added under the changelog's "Added" section labels Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Fixed PR to be added under the changelog's "Fixed" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants