MASTERSTUDY_COURSEDONE::define_trigger()

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


Source Source

File: src/integrations/masterstudy-lms/triggers/masterstudy-coursedone.php

	public function define_trigger() {



		$args = [
			'post_type'      => 'stm-courses',
			'posts_per_page' => 999,
			'orderby'        => 'title',
			'order'          => 'ASC',
			'post_status'    => 'publish',
		];

		$options = Automator()->helpers->recipe->options->wp_query( $args, true, __( 'Any course', 'uncanny-automator' ) );

		$trigger = array(
			'author'              => Automator()->get_author_name(),
			'support_link'        => Automator()->get_author_support_link( $this->trigger_code, 'integration/masterstudy-lms/' ),
			'integration'         => self::$integration,
			'code'                => $this->trigger_code,
			/* translators: Logged-in trigger - MasterStudy LMS */
			'sentence'            => sprintf( esc_attr__( 'A user completes {{a course:%1$s}}', 'uncanny-automator' ), $this->trigger_meta ),
			/* translators: Logged-in trigger - MasterStudy LMS */
			'select_option_name'  => esc_attr__( 'A user completes {{a course}}', 'uncanny-automator' ),
			'action'              => 'stm_lms_progress_updated',
			'priority'            => 20,
			'accepted_args'       => 3,
			'validation_function' => array( $this, 'course_done' ),
			'options'             => [
				[
					'option_code'              => $this->trigger_meta,
					'label'                    => esc_attr_x( 'Course', 'MasterStudy LMS', 'uncanny-automator' ),
					'input_type'               => 'select',
					'required'                 => true,
					'options'                  => $options,
					'relevant_tokens'          => [
						'MSLMSCOURSE'     => esc_attr__( 'Course title', 'uncanny-automator' ),
						'MSLMSCOURSE_ID'  => esc_attr__( 'Course ID', 'uncanny-automator' ),
						'MSLMSCOURSE_URL' => esc_attr__( 'Course URL', 'uncanny-automator' ),
					],
					'custom_value_description' => _x( 'Course ID', 'MasterStudy', 'uncanny-automator' ),
				],
			],
		);

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

		return;
	}