Skip to content
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

Translatepress infinite loop issue for checking capability #204

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions includes/Capability.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class Capability {
* Initialize the class
*/
public function __construct() {
add_filter( 'user_has_cap', [ $this, 'grant_delete_capability_to_specific_roles' ], 10, 4 );
add_filter( 'user_has_cap', array( $this, 'grant_delete_capability_to_specific_roles' ), 10, 4 );
}

/**
* Grant doc delete capabilities to Admin, Editor and
* Grant doc delete capabilities to Admin, Editor and
* weDocs-pro global permission given roles.
*
* @param array $all_caps An array of all the user's capabilities.
Expand All @@ -25,13 +25,22 @@ public function __construct() {
* @return array
*/
public function grant_delete_capability_to_specific_roles( $all_caps, $caps, $args, $user ) {
if ( ! isset( $_GET['post'] ) || 'docs' !== get_post_type( absint( $_GET['post'] ) ) ) {
return $all_caps;
}

$permitted_roles = array( 'administrator', 'editor' );
$delete_caps = array(
$delete_caps = array(
'delete_published_docs' => true,
'delete_docs' => true,
'delete_others_docs' => true,
'delete_private_docs' => true,
);

if ( empty( array_intersect( array_keys( $delete_caps ), $caps ) ) ) {
return $all_caps;
}

if ( wedocs_pro_exists() ) {
$permitted_roles = wedocs_get_permission_settings( 'global_permission', [ 'administrator', 'editor' ] );
}
Expand Down