How do I add IF variable with criteria from $args array?

Question

I’d like to add an IF variable to the following function. IF comment_post_ID = 0 from the $args, do not do $post_comment_id. IF comment_post_ID = NOT 0, proceed with $post_comment_id. How would I do this?

function bp_lesson_sync_add_from_activity_comment( $comment_id, $params, $parent_activity, $activity ) {
global $wpdb;

if ( empty( $comment_parent ) ) {
  $get_comment_parent_id = $wpdb->get_var( "SELECT comment_ID FROM {$wpdb->comments} WHERE user_id = '{$parent_activity->user_id}' AND comment_date_gmt = '{$parent_activity->date_recorded}'" );
} else {
  $get_comment_parent_id = bp_activity_get_meta( $params['parent_id'], "bp_blogs_{$post_type}_comment_id" );
}

// Comment args.
$args = array(
    'comment_post_ID'      => $parent_activity->secondary_item_id,
    'comment_author'       => bp_core_get_user_displayname( $params['user_id'] ),
    'comment_author_email' => $user->user_email,
    'comment_author_url'   => bp_core_get_user_domain( $params['user_id'], $user->user_nicename, $user->user_login ),
    'comment_content'      => $params['content'],
    'comment_type'         => '', // Could be interesting to add 'buddypress' here...
    'comment_parent'       => $get_comment_parent_id,
    'user_id'              => $params['user_id'],
    'comment_approved'     => 1,
);

// Handle timestamps for the WP comment after we've switched to the blog.
$args['comment_date']     = current_time( 'mysql' );
$args['comment_date_gmt'] = current_time( 'mysql', 1 );


// Post the comment.
$post_comment_id = wp_insert_comment( $args );
0
Darryl Syms 2 years 2020-12-18T03:10:22-05:00 0 Answers 10 views 0

Leave an answer

Browse
Browse