WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to disable image uploading in WordPress? (21 posts)

  1. aisajib
    Member
    Posted 4 years ago #

    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?

  2. DigitalMcGrath
    Member
    Posted 4 years ago #

    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');
    
    ?>
  3. aisajib
    Member
    Posted 4 years ago #

    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.

  4. DigitalMcGrath
    Member
    Posted 4 years ago #

    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');
  5. DigitalMcGrath
    Member
    Posted 4 years ago #

    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');
    
    ?>
  6. Anonymous
    Unregistered
    Posted 4 years ago #

    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/

  7. aisajib
    Member
    Posted 4 years ago #

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

    @ adsrikanth, please check your twitter @replies.

  8. DigitalMcGrath
    Member
    Posted 4 years ago #

    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.

  9. aisajib
    Member
    Posted 4 years ago #

    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?

  10. aisajib
    Member
    Posted 4 years ago #

    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

  11. aisajib
    Member
    Posted 4 years ago #

    Plus the media uploader button is still at the QuickPress widget of the dashboard, I've just discovered it. :(

  12. DigitalMcGrath
    Member
    Posted 4 years ago #

    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(__('')); }
  13. aisajib
    Member
    Posted 4 years ago #

    Plus the media uploader button is still at the QuickPress widget of the dashboard, I've just discovered it. :(

  14. Anonymous
    Unregistered
    Posted 4 years ago #

  15. aisajib
    Member
    Posted 4 years ago #

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

  16. aisajib
    Member
    Posted 4 years ago #

    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.

  17. DigitalMcGrath
    Member
    Posted 4 years ago #

    It might be best to disable it for now and go with one of the plugins that adsrikanth suggested.

  18. aisajib
    Member
    Posted 4 years ago #

    Alright, thanks to DigitalMcGrath and adsrikanth.

  19. aisajib
    Member
    Posted 4 years ago #

    adsrikanth,

    uploader button is still remaining at the QuickPress. :(

  20. DigitalMcGrath
    Member
    Posted 4 years ago #

    The QuickPress functionality is located in wp-admin/includes/dashboard.php. You can do a check in this file to see if the user is an admin. Look for this block of code around line 440:

    <?php if ( current_user_can( 'upload_files' ) ) : ?>
    <div id="media-buttons" class="hide-if-no-js">
    <?php do_action( 'media_buttons' ); ?>
    </div>
    <?php endif; ?>

    And change it to:

    <?php if ( current_user_can( 'install_themes' ) ) : ?>
    <div id="media-buttons" class="hide-if-no-js">
    <?php do_action( 'media_buttons' ); ?>
    </div>
    <?php endif; ?>
  21. aisajib
    Member
    Posted 4 years ago #

    Oh God! McGrath that was great!It worked amazing. That adminimize plugin and your tweak both made exactly what I wanted.

    Thank you so much! :) If you have a site or blog you would like me to go through, you are welcome to give me the URL. I will be glad to meet you later.

Topic Closed

This topic has been closed to new replies.

About this Topic