Buddypress_Helpers::all_buddypress_groups( string $label = null, string $option_code = 'BPGROUPS',  $args = array() )


Parameters Parameters

$label

(string) (Optional)

Default value: null

$option_code

(string) (Optional)

Default value: 'BPGROUPS'


Top ↑

Return Return

(mixed)


Source Source

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

	public function all_buddypress_groups( $label = null, $option_code = 'BPGROUPS', $args = array() ) {
		if ( ! $this->load_options ) {


			return Automator()->helpers->recipe->build_default_options_array( $label, $option_code );
		}

		$args = wp_parse_args( $args, array(
			'uo_include_any' => false,
			'uo_any_label'   => esc_attr__( 'Any group', 'uncanny-automator' ),
			'status'         => array( 'public' ),
		) );

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

		global $wpdb;
		$qry     = "SHOW TABLES LIKE '{$wpdb->prefix}bp_groups';";
		$options = array();

		if ( Automator()->helpers->recipe->load_helpers ) {
			if ( $args['uo_include_any'] ) {
				$options[ - 1 ] = $args['uo_any_label'];
			}

			if ( $wpdb->query( $qry ) ) {
				// previous solution was not preparing correct query
				$in_str_arr = array_fill( 0, count( $args['status'] ), '%s' );
				$in_str     = join( ',', $in_str_arr );
				$group_qry  = $wpdb->prepare(
					"SELECT * FROM {$wpdb->prefix}bp_groups WHERE status IN ($in_str)",
					$args['status']
				);

				$results = $wpdb->get_results( $group_qry );

				if ( $results ) {
					foreach ( $results as $result ) {
						$options[ $result->id ] = $result->name;
					}
				}
			}
		}

		$option = [
			'option_code'              => $option_code,
			'label'                    => $label,
			'input_type'               => 'select',
			'required'                 => true,
			'options'                  => $options,
			'custom_value_description' => _x( 'Group ID', 'BuddyPress', 'uncanny-automator' ),
		];


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