Wondering if you can use BF forms to create comments on CPTs conditionally (user provides email)?
Not yet, but it’s in the roadmap ![]()
2 Likes
I needed the same functionality and came up with this code (using info from bricks academy)
function my_form_custom_action( $form ) {
$fields = $form->get_fields();
// $formId = $fields['formId'];
// $postId = $fields['postId'];
// $settings = $form->get_settings();
// $files = $form->get_uploaded_files();
$comment_data = [
'comment_post_ID' => $fields['form-field-postid'],
'comment_author' => $fields['form-field-name'],
'comment_author_email' => $fields['form-field-email'],
'comment_author_url' => 'http://',
'comment_content' => $fields['form-field-comment'],
'comment_type' => 'comment',
'comment_parent' => 0,
'comment_date' => null,
'comment_approved' => 1,
];
try {
wp_insert_comment( wp_slash($comment_data) );
// Success Message
$form->set_result([
'action' => 'my_custom_action',
'type' => 'success',
'message' => esc_html__('New comment', 'bricks'),
]);
} catch (\Exception $e) {
// Error message
$form->set_result([
'action' => 'my_custom_action',
'type' => 'error',
'message' => esc_html__('Something went wrong' . $e->getMessage(), 'bricks'),
]);
}
}
add_action( 'bricks/form/custom_action', 'my_form_custom_action', 10, 1 );
Just choose ‘Custom’ in form actions tab. I’m sure this will work with the native bricks form as well
Create AND update comments, with some comment management features like time allowed to edit, edit reason, perhaps revisions.
Did you already develop this ? Or is it still on the roadmap ?
I cant see any action related to this in Pro Forms.