WordPress.org

Ready to get started?Download WordPress

Forums

remove quick edit from custom post type (11 posts)

  1. Chris
    Member
    Posted 2 years ago #

    Trying to remove the quick edit for a custom post type since overview page loads very slow. Found the reason: register_post_type() anyway, that's another story.

    Question: how can I remove the quick edit function completely from a custom post type list view in the backend?

    (Tried to use settings in options of Custom field template plugin - no luck. Using JavaScript is not an option either since content of quick edit gets loaded)

    Anyone done this in WP 3.1.3?

    Thanx -
    chris

  2. Jeff
    Member
    Posted 2 years ago #

    Chris - Don't know if you got the answer but give this a go (specify your custom post type):

    //removes quick edit from custom post type list
    function remove_quick_edit( $actions ) {
    	global $post;
        if( $post->post_type == 'custom_post_type_name' ) {
    		unset($actions['inline hide-if-no-js']);
    	}
        return $actions;
    }
    
    if (is_admin()) {
    	add_filter('post_row_actions','remove_quick_edit',10,2);
    }
  3. Chris
    Member
    Posted 2 years ago #

    cool - I totally forgot about this til I received your email. Here's what I came up with ...

    Sometimes I need to strip things out before $post is accessible, that's why I use $current_screen in my example:

    /*------------------------------------------------------------------------------------
    	remove quick edit for custom post type videos just to check if less mem consumption
    ------------------------------------------------------------------------------------*/
    add_filter( 'post_row_actions', 'remove_row_actions', 10, 2 );
    function remove_row_actions( $actions, $post )
    {
      global $current_screen;
    	if( $current_screen->post_type != 'videos' ) return $actions;
    	unset( $actions['edit'] );
    	unset( $actions['view'] );
    	unset( $actions['trash'] );
    	unset( $actions['inline hide-if-no-js'] );
    	//$actions['inline hide-if-no-js'] .= __( 'Quick Edit' );
    
    	return $actions;
    }

    I'm not so sure about this one line I commented out. It works perfectly w/o it.

    Would appreciate your input on this -
    Thanks!

  4. Jeff
    Member
    Posted 2 years ago #

    Chris,

    I honestly don't know about the line you've commented out. I've never done that, haven't seen it noted anywhere else and wouldn't think you would want to since you have already removed the array elements. It actually looks a bit funky and would almost think it would break things.

    Anyway, I've used what you already have for quite awhile in my WEBphysiology Portfolio plugin and haven't had any complaints. I only remove the "View" menu item as I was able to work out issues I was having when folks were Quick Editing the custom post type records.

    Cheers,

    Jeff

  5. tnargnai
    Member
    Posted 2 years ago #

    Hi Chris,

    I'm having a similar problem with a custom post type overview page loading very slowly. Up to 15 seconds. There are over 4000 posts for that type.

    All the other custom post over view pages on this site load quickly.

    You mentioned finding the reason and it was something to do with register_post_type(). Could you share with me how you sped up the load time?

    My config for this custom post type is:

    register_post_type('insightdaily',
    		array( 'labels' => array(
    						'name' => _x('Insight Daily', 'post type general name'),
    						'singular_name' => _x('Insight Daily', 'post type singular name'),
    						'add_new' => _x('Add Insight Daily', 'insightdaily'),
    						'add_new_item' => __('Add New Insight Daily'),
    						'edit_item' => __('Edit Insight Daily'),
    						'new_item' => __('New Insight Daily'),
    						'view_item' => __('View Insight Daily'),
    						'search_items' => __('Search Insight Daily'),
    						'not_found' =>  __('No Insight Dailies found'),
    						'parent_item_colon' => ''
    						),
    
    			'public' 		 => true,
    			'publicly_queryable' => true,
    			'register_meta_box_cb' => 'add_insightdaily_custom_fields',
    			'supports' 		 => array(
    				'title',
    				'editor',
    				'revisions'
    			),
    
    			'rewrite' => array(
    				'slug' => 'insight-daily',
    			),
    
    			'hierarchical' => true,
    			#'taxonomies' => array('id_type'),
    			'menu_position' => 3,
    		)
    	);

    Thanks,
    Ian

  6. Dominic
    Member
    Posted 2 years ago #

    Just wanted to say thanks to @Jeff, that code works perfectly for me.

  7. bergonom
    Member
    Posted 1 year ago #

    I am trying these solutions in functions.php, but the global variables seem to have no values in my custom post types.

    For instance, I have simple echo/print_r statements to tell me the values of $post->post_type and $current_screen but they are both always empty. Even when I'm trying to create a plain old Post.

    Any ideas why that might be happening?

    I am using the Custom Content Type Manager plugin to create my custom post types, but I am open to other solutions, including creating my own plugin if necessary.

    Thanks!

  8. bcworkz
    Member
    Posted 1 year ago #

    @bergonom:
    Did you remember to declare global $post; global $current_screen; within the scope of your function?

  9. bergonom
    Member
    Posted 1 year ago #

    Yes, I had declared them within my function.

    I think that Custom Content Type Manager somehow does not register the custom post type.

    I am finding that writing the custom post types manually is working out much better.

    Thanks for your reply!

  10. Chris
    Member
    Posted 1 year ago #

    try call

    echo '<pre>';
    var_dump(get_post_types());

    in your functions.php to see if the custom post types were registered properly.
    Check out this page http://codex.wordpress.org/Function_Reference/register_post_type. It's a good start of creating 'em manually.
    Good luck!

  11. phpzag
    Member
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags