• Resolved Etienne

    (@epipo)


    Hi,

    Thanks for your great plugin :). I just wanted to know if it,s on the roadmap for the next update to get the capabilities right for the dlm_download post type?

    I think it could be really usefull to separate some capabilities (like the others capabilities so that my users can’t edit other’s people downloads). Right now I’ve filtered the register_post_type function but even if I change the capabilities for edit_others_posts and delete_others_posts (and make sure that my author doesn’t have these capabilities) he is still able to modify all the downloads whoever is the author.

    Thanks for your help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Etienne

    (@epipo)

    But maybe I am doing something wrong… Does it work for anybody else?

    Thanks for your help!

    Hello,

    Thanks for reaching out to us.

    I regret to say this is not currently on the roadmap. But this seems interesting and we will discuss it.

    Thread Starter Etienne

    (@epipo)

    In case someone is looking for a way to map custom capabilities to Download Monitor’s custom post type, here is how I did it:

    
    /**
     * Filter the cpt arguments to add capabilitie_type, capabilities and apply the map_meta_cap filter
     */
    add_filter( 'dlm_cpt_dlm_download_args', 'edit_dlm_download_capabilities' );
    function edit_dlm_download_capabilities( $args ) {
    	$args['capability_type'] = 'download';
    	$args['capabilities'] = array(
    		'edit_post'           => 'edit_download',
    		'read_post'           => 'read_download',
    		'delete_post'         => 'delete_download',
    		'edit_posts'          => 'edit_downloads',
    		'edit_others_posts'   => 'edit_others_downloads',
    		'delete_posts'         => 'delete_downloads',
    		'delete_others_posts'   => 'delete_others_downloads',
    		'publish_posts'       => 'publish_downloads',
    		'read_private_posts'  => 'read_private_downloads'
    	);
    	$args['map_meta_cap'] = true;
    	return $args;
    }
    

    Then you can use the map_meta_cap filter to apply your custom capabilities:

    /**
     * Map les capacités aux ressources
     */
    add_filter( 'map_meta_cap', 'map_dlm_downloads_capabilities', 10, 4 );
    function map_dlm_downloads_capabilities( $caps, $cap, $user_id, $args ) {
    
    	if ( 'edit_download' == $cap || 'delete_download' == $cap || 'read_download' == $cap ) {
    		$post = get_post( $args[0] );
    		$post_type = get_post_type_object( $post->post_type );
    
    		$caps = array();
    	}
    
    	if ( 'edit_download' == $cap ) {
    		if ( $user_id == $post->post_author )
    			$caps[] = $post_type->cap->edit_posts;
    		else
    			$caps[] = $post_type->cap->edit_others_posts;
    	}
    
    	elseif ( 'delete_download' == $cap ) {
    		if ( $user_id == $post->post_author )
    			$caps[] = $post_type->cap->delete_posts;
    		else
    			$caps[] = $post_type->cap->delete_others_posts;
    	}
    
    	elseif ( 'read_download' == $cap ) {
    
    		if ( 'private' != $post->post_status )
    			$caps[] = 'read';
    		elseif ( $user_id == $post->post_author )
    			$caps[] = 'read';
    		else
    			$caps[] = $post_type->cap->read_private_posts;
    	}
    
    	return $caps;
    }

    Then you can use any wordpress plugin that allows you to assign user capabilities like User Role Editor or Members.

    • This reply was modified 5 years, 2 months ago by Etienne.
    Thread Starter Etienne

    (@epipo)

    I think it’s important to note that you still have to modify the check for the capabilities by replacing manage_downloads by edit_downloads everywhere it is used in the plugin if you still want to be able to use all the plugin functions.

    Hope this get implemented soon now as I don’t like to edit the plugin’s files…

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Capabilities’ is closed to new replies.