WordPress.org

Ready to get started?Download WordPress

Forums

Remove browse tab (3 posts)

  1. dario77
    Member
    Posted 6 years ago #

    Hi everybody. This is my very first post on WordPress. I was wondering how to remove the browse tab from the upload manager form. I just need the Upload tab and don't want to give users the chance to browse files on the server.

    I've searched everywhere but found nothing

    Thank you so much.

    Dario

  2. Longhair
    Member
    Posted 6 years ago #

    I just tested this out on my localhost, so I don't know if there will be problems down the line...

    Open: upload.php

    Find:

    if ( $pid ) {
    	// 0 => tab display name, 1 => required cap, 2 => function that produces tab content, 3 => total number objects OR array(total, objects per page), 4 => add_query_args
    	$wp_upload_tabs['upload'] = array(__('Upload'), 'upload_files', 'wp_upload_tab_upload', 0);
    	if ( $all_atts && $post_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$post_id'") )
    		$wp_upload_tabs['browse'] = array(__('Browse'), 'upload_files', "wp_upload_tab_browse", $action ? 0 : $post_atts);
    	if ( $post_atts < $all_atts )
    	$wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);
    } else
    	$wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);

    Change To:

    if ( $pid ) {
    	// 0 => tab display name, 1 => required cap, 2 => function that produces tab content, 3 => total number objects OR array(total, objects per page), 4 => add_query_args
    	$wp_upload_tabs['upload'] = array(__('Upload'), 'upload_files', 'wp_upload_tab_upload', 0);
    	if ( $all_atts && $post_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$post_id'") )
    		$wp_upload_tabs['browse'] = array(__('Browse'), 'upload_files', "wp_upload_tab_browse", $action ? 0 : $post_atts);
    	if ( current_user_can('import')
    		if ( $post_atts < $all_atts )
    			$wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);
    } else
    	$wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);

    I added if ( current_user_can('import') ) to make it an Administrator only thing.

    Ref: Capability vs. Role Table

  3. doppledoer
    Member
    Posted 6 years ago #

    Longhair, thanks for the tip, but there is a mistake in your code. You left out the second right bracket after 'import'. For anyone else, copy and paste this instead. It works great.

    if ( $pid ) {
    	// 0 => tab display name, 1 => required cap, 2 => function that produces tab content, 3 => total number objects OR array(total, objects per page), 4 => add_query_args
    	$wp_upload_tabs['upload'] = array(__('Upload'), 'upload_files', 'wp_upload_tab_upload', 0);
    	if ( $all_atts && $post_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$post_id'") )
    		$wp_upload_tabs['browse'] = array(__('Browse'), 'upload_files', "wp_upload_tab_browse", $action ? 0 : $post_atts);
    	if ( current_user_can('import'))
    		if ( $post_atts < $all_atts )
    			$wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);
    } else
    	$wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts);

Topic Closed

This topic has been closed to new replies.

About this Topic