WPP_POLLSUBMIT::define_trigger()

Define and register the trigger by pushing it into the Automator object


Source Source

File: src/integrations/wp-polls/triggers/wpp-pollsubmit.php

	public function define_trigger() {



		global $wpdb;

		// Get Poll Questions
		$questions = $wpdb->get_results( "SELECT pollq_id, pollq_question FROM $wpdb->pollsq ORDER BY pollq_id DESC" );

		$questions_options = array();

		$questions_options[0] = __( 'Any poll', 'uncanny-automator-pro' );

		foreach ( $questions as $question ) {
			$title = $question->pollq_question;

			if ( empty( $title ) ) {
				$title = sprintf( __( 'ID: %s (no title)', 'uncanny-automator-pro' ), $question->pollq_id );
			}

			$questions_options[ $question->pollq_id ] = $title;
		}

		$trigger = array(
			'author'              => Automator()->get_author_name( $this->trigger_code ),
			'support_link'        => Automator()->get_author_support_link( $this->trigger_code, 'integration/wp-polls/' ),
			'integration'         => self::$integration,
			'code'                => $this->trigger_code,
			/* translators: Logged-in trigger - LearnDash */
			'sentence'            => sprintf( esc_attr__( 'A user submits {{a poll:%1$s}}', 'uncanny-automator' ), $this->trigger_meta ),
			/* translators: Logged-in trigger - LearnDash */
			'select_option_name'  => esc_attr__( 'A user submits {{a poll}}', 'uncanny-automator' ),
			'action'              => 'wp_polls_vote_poll_success',
			'priority'            => 1,
			'accepted_args'       => 0,
			'validation_function' => array( $this, 'poll_success' ),
			'options'             => [
				Automator()->helpers->recipe->field->select_field(
					$this->trigger_meta,
					esc_attr__( 'Poll', 'uncanny-automator' ),
					$questions_options,
					null,
					'',
					false,
					[
						$this->trigger_meta                   => __( 'Poll question', 'uncanny-automator' ),
						$this->trigger_meta . '_ANSWERS'      => __( 'Poll answers', 'uncanny-automator' ),
						$this->trigger_meta . '_START'        => __( 'Poll start date', 'uncanny-automator' ),
						$this->trigger_meta . '_END'          => __( 'Poll end date', 'uncanny-automator' ),
						$this->trigger_meta . '_WPPOLLANSWER' => __( 'Poll selected answer(s)', 'uncanny-automator' ),
					]
				),
			],
			'options_group'       => array(),
		);

		Automator()->register->trigger( $trigger );

		return;
	}