Support » Plugin: DCO Comment Attachment » Limit usage to specific CPT

  • Resolved Vlasta Ott

    (@plastique)


    Hey, thanks for this awesome plugin. Would it be possible to select on which CPT will the plugin be active? I have a few custom post types and don’t want to let users upload files on some of them. A hook (filter) would be fine – don’t need a GUI.

    thanks

    • This topic was modified 3 months, 2 weeks ago by Vlasta Ott.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Denis Yanchevskiy

    (@denisco)

    Hello @plastique,

    I’m sorry to be late with the reply.

    At the moment, the plugin does not have a dedicated hook for it. But you can use the dco_ca_disable_attachment_field hook.

    Try something like this:

    function my_dco_ca_disable_attachment_field( $disable ) {
    	$restricted_cpts = [ 'book', 'movie' ];
    	
    	$post_id = url_to_postid( $_SERVER[ 'REQUEST_URI' ] );
    	$post_type = get_post_type( $post_id );
    	
    	if( in_array( $post_type, $restricted_cpts ) ) {
    		return true;
    	}
    	
    	return $disable;
    }
    
    add_filter( 'dco_ca_disable_attachment_field', 'my_dco_ca_disable_attachment_field' );

    In this example, the attachment field will be disabled for book and movie types.

    Plugin Author Denis Yanchevskiy

    (@denisco)

    Marking as resolved. Feel free to reopen this topic, or create a new one if you have another questions.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.