Events_Manager_Helpers::all_em_events( $label = null,  $option_code = 'EMALLEVENTS',  $args = array() )


Source

File: src/integrations/events-manager/helpers/events-manager-helpers.php

	public function all_em_events( $label = null, $option_code = 'EMALLEVENTS', $args = array() ) {
		if ( ! $label ) {
			$label = __( 'Event', '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'] : '';
		$any_option   = key_exists( 'any_option', $args ) ? $args['any_option'] : false;
		$options      = array();

		if ( isset( $any_option ) && $any_option == true ) {
			$options['-1'] = __( 'Any event', 'uncanny-automator' );
		}

		global $wpdb;
		$table = $wpdb->prefix . 'em_events';
		$query = "SELECT event_id,event_name FROM  $table WHERE event_status = 1 ORDER BY event_name";

		$all_events = $wpdb->get_results( $query );

		foreach ( $all_events as $event ) {
			$title = $event->event_name;
			if ( empty( $title ) ) {
				$title = sprintf( __( 'ID: %s (no title)', 'uncanny-automator' ), $event->event_id );
			}
			$options[ $event->event_id ] = $title;
		}

		$option = [
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'supports_tokens' => $token,
			'is_ajax'         => $is_ajax,
			'fill_values_in'  => $target_field,
			'endpoint'        => $end_point,
			'options'         => $options,
			'relevant_tokens' => [
				$option_code          => __( 'Event title', 'uncanny-automator' ),
				$option_code . '_ID'  => __( 'Event ID', 'uncanny-automator' ),
				$option_code . '_URL' => __( 'Event URL', 'uncanny-automator' ),
			],
		];

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