Enable Editor-Role to view Free Downloads Log?

Posted by: David Lee

29th June 2018, 9:07 pm

David Lee

@squareonemediadlxwebs

29 Jun 2018
9:07 pm

Hi, I'm using Free Downloads Woocommerce Pro plugin, activated on a subsite of multisite install.

I'd like to enable someone with Editor role to be able to view the Tracked Free Download Logs.

I've been experimenting with the 'kw_somdn_downloads_capabilities' filter, as well as installed plugins "Menu Editor Pro" and "User Role Editor"...   but am having no luck.

Is this possible without modifying the plugin code? .. Could you please advise?

Thanks!

  • Richard Webster

    @rwebster

    29 Jun 2018
    9:14 pm

    Untested but you could try this:

    add_filter( 'somdn_downloads_capabilities', 'somdn_downloads_capabilities_editor', 20, 1 );
    function somdn_downloads_capabilities_editor( $args ) {
    
    	$editor_capabilities = array(
    		'edit_post'          => 'edit_posts',
    		'read_post'          => 'edit_posts',
    		'delete_post'        => 'edit_posts',
    		'edit_posts'         => 'edit_posts',
    		'edit_others_posts'  => 'edit_posts',
    		'delete_posts'       => 'edit_posts',
    		'publish_posts'      => 'edit_posts',
    		'read_private_posts' => 'edit_posts',
    		'create_posts' => false
    	);
    
    	return $editor_capabilities;
    
    }

    The "edit_posts" capability is for editors and above. More info here.

    For any of the above abilities like delete posts that you don't want editors to be able to do, use the "update_core" capability instead of "edit_posts".

    Last modified: 29th June 2018, 9:21 pm by Richard Webster

  • David Lee

    @squareonemediadlxwebs

    29 Jun 2018
    9:45 pm

    Thanks for the quick reply.  I've implemented your filter and I'm still getting the ..

    "You need higher level of permission.
    Sorry, you are not allowed to edit posts in this post type."

    Thanks

  • David Lee

    @squareonemediadlxwebs

    29 Jun 2018
    11:21 pm

    Although I've yet to wrap my brain around how the 'map_meta_cap' works.. setting it to false seems to do the trick.

    Combining that and your prev code.. I'm setting the args in the 'somdn_downloads_args' filter, at register_post_type().

    (dunno why I didn't notice that filter before)

    add_filter( 'somdn_downloads_args', 'dlx_somdn_downloads_args');
    
    function dlx_somdn_downloads_args($somdn_tracked_downloads_args) {
    
            $somdn_tracked_downloads_args[capabilities] = array(
                'edit_post'          => 'edit_posts',
                'read_post'          => 'edit_posts',
                'delete_post'        => 'edit_posts',
                'edit_posts'         => 'edit_posts',
                'edit_others_posts'  => 'edit_posts',
                'delete_posts'       => 'edit_posts',
                'publish_posts'      => 'edit_posts',
                'read_private_posts' => 'edit_posts',
                'create_posts' => false
            );
    
            $somdn_tracked_downloads_args[map_meta_cap] = false;
    
        return $somdn_tracked_downloads_args;
    }
  • Richard Webster

    @rwebster

    30 Jun 2018
    7:06 am

    Awesome mate. Worth checking to make sure an account with less permissions than an Editor is unable to access them.

This topic is closed to new replies.

Looking for Square One Media? Check this post