• Resolved Liltiger

    (@liltiger)


    Hi There!

    First off, I just want to thank you for your awesome plugin! I’m bummed to find out that it’s not working with the Limit Posts plugin, by Plugin Central, when I create a new user role with your plugin.

    For example: I’ve added the new user role, contributor_basic with your plugin. The Limit Posts plugin does not limit the posts for that role. However, when I add a user role manually in the functions file using: $result = add_role( 'contributor_basic', __( 'Contributor Basic' ), array( ) ); the Limit Posts plugin does its job.

    Is there a way to make the Limit Posts plugin recognize new user roles created with this plugin? I’d love to continue using both!

    Best Regards

    https://www.ads-software.com/plugins/user-role-editor/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Vladimir Garagulya

    (@shinephp)

    Hi,

    User Role Editor uses the same WordPress API to add new roles, so there is no differences here.
    “Limit Posts” author supposes that user role ID and user role name are the same. It stores at the plugins settings page role name, but when tries to apply the rule get the role ID of current user and just converts it’s 1st letter to the uppercase.

    private function getCurrentUserRole(){
    	global $current_user;
    
    	$userRole = $current_user->roles;
    
    	return ucfirst($userRole[0]);
    }

    So for the ‘Contributor Copy (contributor-copy)’ role, which I tested, the automatically build name ‘Contributor-copy’ will never match with the real one ‘Contributor Copy’, which I tested. The rule is not applied for this case for the custom roles created with User Role Editor.

    To get a valid role name for a role ID a developer should take it from the $wp_roles global instead.

    Thread Starter Liltiger

    (@liltiger)

    Hi Vladimir,

    Thanks for the prompt response and for investigating this. I REALLY appreciate your help!

    I don’t fully understand $wp_roles, but with some help and your direction, we modified the code below to make it work with the user roles I created:

    //filter out any rules not for a user role
    	private function filterRulesForUserRole($inputRules, $userRole){
    		$filteredRules = array();
    
    		foreach($inputRules['rule'] as $rule){
    			$userOrRole = $this->getUserOrRole($rule);
    			if($userOrRole != 'role'){
    				$filteredRules[] = $rule;
    			}
    			else{
    				<strong>if((strtoupper(str_replace('_', ' ', $rule['role'])) == strtoupper(str_replace('_', ' ', $userRole))) || $rule['role'] == 'ALL'){</strong>
    					$filteredRules[] = $rule;
    				}
    			}
    		}
    
    		return $filteredRules;
    	}
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Plugin Not Compatible With Limit Posts Plugin’ is closed to new replies.