PeepSo_Helpers::get_users( $label = null,  $option_code = 'PPUSERS',  $args = array(),  $bynames = false )


Parameters Parameters

(Required) peepso users


Source Source

File: src/integrations/peepso/helpers/peepso-helpers.php

	public function get_users( $label = null, $option_code = 'PPUSERS', $args = array(), $bynames = false ) {

		if ( ! $label ) {
			$label = esc_attr__( 'PeepSo member', 'uncanny-automator' );
		}

		$args = wp_parse_args(
			$args,
			array(
				'uo_include_any' => false,
				'uo_any_label'   => esc_attr__( 'Any PeepSo member', 'uncanny-automator' ),
			)
		);

		$options = array();

		if ( $args['uo_include_any'] ) {
			$options['-1'] = $args['uo_any_label'];
		}

		global $wpdb;
		$users = $wpdb->get_results( "SELECT * FROM `{$wpdb->prefix}peepso_users`", ARRAY_A );

		if ( count( $users ) > 0 ) {
			foreach ( $users as $user ) {
				if ( false === $bynames ) {
					$options[ $user['usr_id'] ] = get_user_by( 'id', $user['usr_id'] )->display_name;
				} else {
					$user_by_id = get_user_by( 'id', $user['usr_id'] );
					if ( $user_by_id instanceof \WP_User ) {
						$options[ $user['usr_id'] ] = sprintf( '%s %s [%s]', $user_by_id->last_name, $user_by_id->first_name, $user_by_id->user_email );
					} else {
						$options[ $user['usr_id'] ] = '#' . $user['usr_id'];
					}
				}
			}
		}

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'options'         => $options,
			'relevant_tokens' => array(),
		);

		return apply_filters( 'uap_option_peepso_all_users', $option );
	}