Skip to content

Instantly share code, notes, and snippets.

@grantcodes
Created September 21, 2015 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grantcodes/fe4996b73990780484a4 to your computer and use it in GitHub Desktop.
Save grantcodes/fe4996b73990780484a4 to your computer and use it in GitHub Desktop.
An updated function for the WooCommerce product vendors plugin
/**
* Get admins for vendor
* @param int $vendor_id ID of vendor
* @return arr Array of user objects
*/
function get_vendor_admins( $vendor_id = 0 ) {
global $wc_product_vendors;
$admins = array();
if( $vendor_id > 0 ) {
$vendor_info = get_option( $wc_product_vendors->token . '_' . $vendor_id );
if ( $admin_ids = $vendor_info['admins'] ) {
foreach ( $admin_ids as $admin_id ) {
if ( is_int( $admin_id ) ) {
$admins[] = $admin_id;
} elseif ( is_string( $admin_id ) ) {
foreach ( explode( ',', $admin_id ) as $id ) {
$admins[] = trim( $id );
}
}
}
}
if ( count( $admins ) > 0 ) {
$args = array(
'include' => $admins
);
$admins = get_users( $args );
}
}
return $admins;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment