• Resolved Chris

    (@christof15)


    Hi, I would like to remove the WP-Optimize column from the Media page. I know I can do it through Screen Settings but I’d rather do it with:

    add_filter('manage_media_columns','wpse_77687_remove_media_columns');
    function wpse_77687_remove_media_columns($columns) {
        $roles = array('dailyadmin', 'editor');
        foreach($roles as $role) {
            if (current_user_can($role)) {
    	  unset($columns['imsanity']); /* Column ID value */
              unset($columns['wpo_smush']);
    	break;
            }
        }
        return $columns;
    }

    This unfortunately is not working. What am I doing wrong?
    Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support vupdraft

    (@vupdraft)

    Is there any particular reason why you are unwilling to do it through the settings?

    Thread Starter Chris

    (@christof15)

    Yes, i want to control which users/groups can and can’t use it from the mediapage.

    Plugin Support vupdraft

    (@vupdraft)

    You are not quite using your user capabilities correctly here. You are mixing them up with WP roles.

    User capabilities should be things link user can install_plugins, update_core or edit_posts.

    Try something like the following

    function wpse_77687_remove_media_columns($columns)?
    
    {
    
    ? ? // For admin level roles,? add the smush functionality ?
    
    ? ? if ( current_user_can(install_plugins) )
    
    ? ? {
    
    ? ? ? ? $columns[‘imnsanity’];
            $columns[‘wpo_smush’];
    
    ? ? }
    
    ? ? // for other roles, hide the smush functionality
    
    ? ? elseif ( current_user_can(edit_posts) )
    
    ? ? {
    
    ? ? ? unset($columns['imsanity']); /* Column ID value */
    
    ? ? ? unset($columns['wpo_smush']);
    
    ? ? return $columns;}
    
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Remove WP-Optimize from Media Column’ is closed to new replies.