WP_SUBMITCOMMENT::define_trigger()

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


Source Source

File: src/integrations/wp/triggers/wp-submitcomment.php

	public function define_trigger() {


		$all_post_types = Automator()->helpers->recipe->wp->options->all_post_types( null, 'WPPOSTTYPES', [
			'token'        => false,
			'is_ajax'      => true,
			'target_field' => $this->trigger_meta,
			'endpoint'     => 'select_all_post_from_SELECTEDPOSTTYPE',
		] );

		// now get regular post types.
		$args = [
			'public'   => true,
			'_builtin' => true,
		];

		$output         = 'object';
		$operator       = 'and';
		$options        = array();
		$options['- 1'] = __( 'Any post type', 'uncanny-automator' );
		$post_types     = get_post_types( $args, $output, $operator );
		if ( ! empty( $post_types ) ) {
			foreach ( $post_types as $post_type ) {
				$options[ $post_type->name ] = esc_html( $post_type->labels->singular_name );
			}
		}
		$options                   = array_merge( $options, $all_post_types['options'] );
		$all_post_types['options'] = $options;
		$trigger                   = array(
			'author'              => Automator()->get_author_name( $this->trigger_code ),
			'support_link'        => Automator()->get_author_support_link( $this->trigger_code, 'integration/wordpress-core/' ),
			'integration'         => self::$integration,
			'code'                => $this->trigger_code,
			/* translators: Logged-in trigger - WordPress */
			'sentence'            => sprintf( esc_attr__( 'A user submits a comment on {{a post:%1$s}} {{a number of:%2$s}} time(s)', 'uncanny-automator' ), $this->trigger_meta, 'NUMTIMES' ),
			/* translators: Logged-in trigger - WordPress */
			'select_option_name'  => esc_attr__( 'A user submits a comment on {{a post}}', 'uncanny-automator' ),
			'action'              => 'comment_post',
			'priority'            => 90,
			'accepted_args'       => 3,
			'validation_function' => array( $this, 'submitted_comment' ),
			'options'             => [
				Automator()->helpers->recipe->options->number_of_times(),
			],
			'options_group'       => [
				$this->trigger_meta => [
					$all_post_types,
					Automator()->helpers->recipe->field->select_field(
						$this->trigger_meta,
						__( 'Post', 'uncanny-automator-pro' ),
						[],
						null,
						false,
						false,
						[
							$this->trigger_meta          => esc_attr__( 'Page title', 'uncanny-automator' ),
							$this->trigger_meta . '_ID'  => esc_attr__( 'Page ID', 'uncanny-automator' ),
							$this->trigger_meta . '_URL' => esc_attr__( 'Page URL', 'uncanny-automator' ),
						]
					),
				],
			],
		);

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

		return;
	}