Gamipress_Helpers::list_gp_award_types( string $label = null, string $option_code = 'GPAWARDTYPES', array $args = array() )


Parameters Parameters

$label

(string) (Optional)

Default value: null

$option_code

(string) (Optional)

Default value: 'GPAWARDTYPES'

$args

(array) (Optional)

Default value: array()


Top ↑

Return Return

(mixed)


Source Source

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

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


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

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

		$token        = key_exists( 'token', $args ) ? $args['token'] : false;
		$is_ajax      = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
		$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
		$end_point    = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
		$options      = array();

		global $wpdb;
		if ( Automator()->helpers->recipe->load_helpers ) {

			//$posts = Automator()->helpers->recipe->options->wp_query( [ 'post_type' => 'achievement-type' ] );
			$posts = $wpdb->get_results( "SELECT ID, post_name, post_title, post_type
											FROM $wpdb->posts
											WHERE post_type LIKE 'achievement-type' AND post_status = 'publish' ORDER BY post_title ASC" );
			if ( ! empty( $posts ) ) {
				foreach ( $posts as $post ) {
					$options[ $post->post_name ] = $post->post_title;
				}
			}
			/* translators: GamiPress achievement type */
			$options['points-award'] = esc_attr__( 'Points awards', 'uncanny-automator' );
			/* translators: GamiPress achievement type */
			$options['step'] = esc_attr__( 'Step', 'uncanny-automator' );
			/* translators: GamiPress achievement type */
			$options['rank-requirement'] = esc_attr__( 'Rank requirement', 'uncanny-automator' );
		}
		$type = 'select';

		$option = [
			'option_code'              => $option_code,
			'label'                    => $label,
			'input_type'               => $type,
			'required'                 => true,
			'supports_tokens'          => $token,
			'is_ajax'                  => $is_ajax,
			'fill_values_in'           => $target_field,
			'endpoint'                 => $end_point,
			'options'                  => $options,
			'custom_value_description' => _x( 'Achievement type slug', 'GamiPress', 'uncanny-automator' ),
		];

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