WP_SUBMITCOMMENT::submitted_comment( int $comment_id, int|string $comment_approved, array $commentdata )
Validation function when the trigger action is hit
Contents
Parameters Parameters
- $comment_id
-
(Required) The comment ID.
- $comment_approved
-
(Required) 1 if the comment is approved, 0 if not, 'spam' if spam.
- $commentdata
-
(Required) Comment data.
Source Source
File: src/integrations/wp/triggers/wp-submitcomment.php
public function submitted_comment( $comment_id, $comment_approved, $commentdata ) { $user_id = get_current_user_id(); $post_type = get_post_type( $commentdata['comment_post_ID'] ); // We need backword compatibility along with new change $recipes = Automator()->get->recipes_from_trigger_code( $this->trigger_code ); $conditions = $this->match_condition( $commentdata['comment_post_ID'], $post_type, $recipes, $this->trigger_meta, $this->trigger_code ); if ( ! $conditions ) { return; } $post_type = get_post_type_object( $post_type ); if ( ! empty( $conditions ) ) { foreach ( $conditions['recipe_ids'] as $recipe_id ) { if ( ! Automator()->is_recipe_completed( $recipe_id, $user_id ) ) { $args = [ 'code' => $this->trigger_code, 'meta' => $this->trigger_meta, 'recipe_to_match' => $recipe_id, 'post_id' => $commentdata['comment_post_ID'], 'user_id' => $user_id, ]; $arr = Automator()->maybe_add_trigger_entry( $args, false ); if ( $arr ) { foreach ( $arr as $result ) { if ( true === $result['result'] ) { $trigger_meta = [ 'user_id' => $user_id, 'trigger_id' => $result['args']['trigger_id'], 'trigger_log_id' => $result['args']['get_trigger_id'], 'run_number' => $result['args']['run_number'], ]; // Post $trigger_meta['meta_key'] = 'WPPOSTCOMMENTS'; $trigger_meta['meta_value'] = $commentdata['comment_post_ID']; Automator()->insert_trigger_meta( $trigger_meta ); // Post Type Token $trigger_meta['meta_key'] = 'WPPOSTTYPES'; $trigger_meta['meta_value'] = maybe_serialize( $post_type->labels->singular_name ); Automator()->insert_trigger_meta( $trigger_meta ); Automator()->maybe_trigger_complete( $result['args'] ); } } } } } } }
Expand full source code Collapse full source code View on Github