Skip to content

Instantly share code, notes, and snippets.

@anthonysbrown
Created May 25, 2022 18:43
Show Gist options
  • Save anthonysbrown/9175404ab2533c375d82ac7d3df0ef62 to your computer and use it in GitHub Desktop.
Save anthonysbrown/9175404ab2533c375d82ac7d3df0ef62 to your computer and use it in GitHub Desktop.
Add email to dropdowns on smarty document manager
<?php
add_filter('sp_cdm/admin/fileview/dropdown', function($dropdown){
$arrParts = explode("</select>", $dropdown);
foreach($arrParts as &$part){
if($selPos = strpos($part, "<select")){
$part = substr($part, 0, $selPos);
}
}
$dropdown = implode("", $arrParts);
$selected = sanitize_text_field( cdm_var( 'id' ) );
$siteusers = get_users(); // you can pass filters and option
if (count($siteusers) > 0){
$dropdown .= '<select name="user_uid" id="user_uid" class="user_uid"><option value="">Choose a user</option>';
foreach ($siteusers as $user) {
$dropdown .= '<option value="' . $user->ID . '">'.$user->user_nicename . ' ('.$user->user_email .')</option>';
}
$dropdown .= '</select>';
$dropdown = str_replace('value="' . $selected . '"','value="' . $selected . '" selected="selected"', $dropdown);
}
return $dropdown;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment