How to change Elgg's default user/group profile icons

Make a folder "default_icons" directly inside your plugin's folder and add PNG images prefixed with either "user-" or "group-". Example:

myPlugin
/default_icons
/group-defaultsmall.png
/user-defaultsmall.png

Icon URLs are set by the "entity:icon:url" plugin hook, so we add a handler to look for and replace the default paths. (Since you may not have a full set of replacements, the handler below first checks that your replacement PNG exists.)

elgg_register_plugin_hook_handler('entity:icon:url', 'all', 'myPlugin_alter_default_icons', 999);

function myPlugin_alter_default_icons($hook, $type, $returnValue, $params) {
    $file = '';
    if (0 === strpos($returnValue, 'mod/groups/graphics/default')) {
        $file = __DIR__ . '/default_icons/group-' . substr($returnValue, 20);
    } elseif (0 === strpos($returnValue, '_graphics/icons/user/default')) {
        $file = __DIR__ . '/default_icons/user-' . substr($returnValue, 21);
    }
if ($file) {
$file = str_replace('.gif', '.png', $file); // our designer wants PNG files
}
    if (file_exists($file)) {
        $returnValue = "mod/" . basename(__DIR__) . substr($file, strlen(__DIR__));
    }
    return $returnValue;
}

If you want to stick with GIF images, just remove the line with str_replace().

Navigation