Hi.

I want to have user photo in their profile, but only admin to be allowed to upload the photo. I have enabled picture support in User Settings but I do not see where I can not allow users to upload their own picture in permissions. Is there a way to not allow users to upload thier own profile photo?

Comments

WorldFallz’s picture

I don't believe you can do this through the existing ui, but you should be able to hook_form_alter the upload fieldset out of the form for everyone but the administrator.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

waynedrupal’s picture

Not sure how to do this. Any recommondations?

WorldFallz’s picture

Create a little module that implements hook_form_alter on the profile form and put something like this in it (just a guess, totally untested):

<?php
/**
* Implementation of hook_form_alter().
*/
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  global $user; 
  if ($form_id == 'user_profile_form' && $user != 1){
    unset($form['picture']);
  }
}
?>

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

vm’s picture

where "mymodule" = the name of your module. ie: user_picture_module_form_alter

The user will also need to check out the developer documentation to understand how to create a .info file and a .module file for this.

Rob T’s picture

I found this nifty module - x_contact_option - to restrict certain roles from creating their own contact form in their profiles.

I looked at the few lines of code, and figured I could do the same with the picture uploads.

Thanks for the unset($form['picture']);, because I was using unset($form['picture_upload']); to no avail.

Here's my resulting .module that restricts roles (via permissions) from using the picture upload form...

<?php
/**
 * implementation of hook_perm
 * only users who belong to roles with this permission can
 * use picture upload form in profile
 */
function x_picture_option_perm(){
	return array('upload picture to profile');	
}

/**
 * implementation of hook_form_alter
 * hide this option for users without the privilege
 */
function x_picture_option_form_alter(&$form, $form_state, $form_id){
	if (arg(0)=='user' && arg(2)=='edit'){
		if (!user_access('upload picture to profile')){
			unset($form['picture']);
		}
	}
}

And the chinsey little .info file...

name = x_picture_option
description = enable / disable profile picture upload to individual users 
version = "6.x-dev"
project = "x_picture_option"
core = "6.x"
Agxcix’s picture

This is exactly what I need. I copied the text above into x_picture.info and x_picture.module and then installed the module. I didn't have any errors but nothing seems to happen. Should I see a "upload picture to profile" check box in "/admin/user/permissions?" I don't and I'm not sure what I am doing wrong.

michelle’s picture

See http://drupal.org/project/avatar_selection

Michelle

--------------------------------------
See my Drupal articles and tutorials or come check out life in the Coulee Region.

waynedrupal’s picture

Thanks Michelle. I was hoping this would do the trick, but it seems that the admin or user/1 would not be able to edit or add photo is disable users ability to change or upload photo.

I only want the admin to be able to upload a photo.

Any other thoughts?

johnhanley’s picture

Do as WorldFallz illustrated.

A slightly more flexible variation would be to show the user picture upload form element to anyone with "administer users" permission. Note the field name 'picture_upload' correction.

/**
* Implementation of hook_form_alter().
*/
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  global $user;
  if ($form_id == 'user_profile_form' && !user_access('administer users')){
    unset($form['picture_upload']);
  }
}

-------------------------------------------------------

"If you don't read the newspaper you are uninformed;
if you do read the newspaper you are misinformed."
-- Mark Twain

bwinett’s picture

FYI, to make this work I had to change your "unset" command to:

unset($form['picture']);

Thanks for the code!