WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] How to disable image uploading in WordPress?

[Resolved] How to disable image uploading in WordPress?

  • Hi everyone, I’ve been using WordPress for more than a year and recently I’ve decided to create a WordPress team site which will have multi author. But I was not willing to use WP MU.

    I’m trying out WP 3 RC 1 and it’s perfect for my need. However, I’m willing to disable media uploading feature for all my authors because of short space of hosting. I’m willing to ask my authors to upload image elsewhere, such as Flickr or Tinypic, and then put the photos into the post through a direct link.

    But I want the image/media uploader to be disabled for authors. Is there any trick to do that?

Viewing 15 replies - 1 through 15 (of 20 total)
  • DigitalMcGrath
    Member

    @digitalmcgrath

    Create a file in your plugin directory. Then use the code below in that file. Once uploaded to your server, just activate the plugin like any other. The code below will disable the media uploading for anyone who is not an admin.

    <?php
    /*
    Plugin Name: Disable Media Uploader
    Plugin URI: http://www.YourSite.com
    Version: v 1.0
    Author: Your Name
    Description: This will disable the media upload function of posts for users who are not admins.
    */
    
    function removemediabuttons()
    {
    	if($user->wp_user_level >= 1) {
    		remove_action( 'media_buttons', 'media_buttons' );
    	}
    }
    add_action('admin_head','removemediabuttons');
    
    ?>

    I’ve done as said, the plugin was shown there and I activated it. It was successfully activated. Then I logged in as an author (with a different username) and noticed that the media uploader button was still there.

    I need further help. And thanks for your quick reply, McGrath.

    DigitalMcGrath
    Member

    @digitalmcgrath

    Try this:

    function removemediabuttons()
    {
    	global $current_user;
          get_currentuserinfo();
    		if($current_user->user_level != 10) {
    		remove_action( 'media_buttons', 'media_buttons' );
    	}
    }
    add_action('admin_head','removemediabuttons');

    DigitalMcGrath
    Member

    @digitalmcgrath

    I added a little more functionality to this plugin so it will remove the “Media” label from the admin menu as well:

    <?php
    /*
    Plugin Name: Disable Media Uploader
    Plugin URI: http://www.YourSite.com
    Version: v 1.0
    Author: Your Name
    Description: This will disable the media upload function of posts.
    */
    
    function removemediabuttons()
    {
    	if( !(current_user_can('install_themes')) ) {
    		remove_action( 'media_buttons', 'media_buttons' );
    	}
    
    }
    add_action('admin_head','removemediabuttons');
    
    function remove_menus () {
    global $menu;
    if( (current_user_can('install_themes')) ) { $restricted = ''; } // check if admin and hide these for admins
    else { $restricted = array(__('Media')); } // hide these for other roles
    end ($menu);
    while (prev($menu)){
    $value = explode(' ',$menu[key($menu)][0]);
    if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
    }
    }
    add_action('admin_menu', 'remove_menus');
    
    ?>

    There are a couple of plugins to effectively manage roles on WordPress

    Adminize and role manager plugins
    thenextweb.com/2009/01/22/how-to-manage-roles-and-capabilities-effectively-on-wordpress/

    @ McGrath, you’ve given me two separate bunch of codes. Which one should I apply?

    @ adsrikanth, please check your twitter @replies.

    DigitalMcGrath
    Member

    @digitalmcgrath

    If you use the latest one I posted, it will remove the “Media” label from your admin menu as well as from the add post page.

    Thanks a lot McGrath! That was what I’d been looking for.

    I wish I could write plugins for these little tweaks. 🙁 Do you have any site for me to learn these from?

    The plugin worked but these warning messages are shown repeatedly in my dashboard.

    Warning: in_array(): Wrong datatype for second argument in /wp-content/plugins/disable media.php on line 25

    Plus the media uploader button is still at the QuickPress widget of the dashboard, I’ve just discovered it. 🙁

    DigitalMcGrath
    Member

    @digitalmcgrath

    Ok, lets start with the error you are seeing. Change the following line:

    if( (current_user_can('install_themes')) ) { $restricted = ''; }

    to:

    if( (current_user_can('install_themes')) ) { $restricted = array(__('')); }

    Plus the media uploader button is still at the QuickPress widget of the dashboard, I’ve just discovered it. 🙁

    Done. It’s working. What should I do to remove media uploader from the QuickPress widget?

    Corrected, but the messages still exist. I think something is wrong with the 25th line.

    For your information, the warning message isn’t shown in other author pages. Only I get this.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘[Resolved] How to disable image uploading in WordPress?’ is closed to new replies.