WP_POSTRECEIVESCOMMENT::define_trigger()


Source Source

File: src/integrations/wp/triggers/wp-postreceivescomment.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        = [];
		$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's {{post:%1\$s}} receives a comment", 'uncanny-automator' ), $this->trigger_meta ),
			/* translators: Logged-in trigger - WordPress */
			'select_option_name'  => esc_attr__( "A user's {{post}} receives a comment", 'uncanny-automator' ),
			'action'              => 'comment_post',
			'priority'            => 90,
			'accepted_args'       => 3,
			'validation_function' => array( $this, 'post_receives_comment' ),
			'options'             => [],
			'options_group'       => [
				$this->trigger_meta => [
					$all_post_types,
					Automator()->helpers->recipe->field->select_field(
						$this->trigger_meta,
						__( 'Post', 'uncanny-automator' ),
						[],
						null,
						false,
						false,
						[
							'POSTTITLE'          => esc_attr__( 'Post title', 'uncanny-automator' ),
							'POSTAUTHORDN'       => esc_attr__( 'Post author', 'uncanny-automator' ),
							'POSTCOMMENTCONTENT' => esc_attr__( 'Comment', 'uncanny-automator' ),
							'POSTCOMMENTDATE'    => esc_attr__( 'Comment date', 'uncanny-automator' ),
							'POSTCOMMENTEREMAIL' => esc_attr__( 'Commenter email', 'uncanny-automator' ),
							'POSTCOMMENTERNAME'  => esc_attr__( 'Commenter name', 'uncanny-automator' ),
							'POSTCOMMENTSTATUS'  => esc_attr__( 'Commenter status', 'uncanny-automator' ),
						]
					),
				],
			],
		);

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