Black Friday / Cyber Monday Weekend Sale!

25 - 28 November 2022

Sale ends in:

Days
Hours
Minutes
Seconds


Use code BFCM2022 for 40% off at the checkout.

Support for Themes with Front-end Forms

Updated

Sometimes, a WordPress theme will add a post directly to the database instead of transitioning it between post statuses. When this happens (usually via a front-end form of some kind), BNFW can’t pick up the notification as it passes between draft and publish, or draft and scheduled, etc.

In order to add support for your theme, please add the following code to your theme’s functions.php file, replacing the word ‘theme_name’ on line 2 with the name of your theme.

1
2
3
4
5
function bnfw_insert_post_hook_for_theme( $themes ) {
$themes[] = 'theme_name';
return $themes;
}
add_filter( 'bnfw_insert_post_themes', 'bnfw_insert_post_hook_for_theme' );

This isn’t always guaranteed to work but it’s a good start. If you need to add support for plugins with front-end forms, please see this help document.

Alternatively, if you’re adding your own front-end form via a template file in your theme, you can use this code snippet as a starting point:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Create the new post
$new_post = wp_insert_post(array(
'post_title' => $post_title,
'post_content' => $post_content,
'post_category' => $cat,
'post_status' => "draft",
'post_type' => $post_type
));
$post_to_transition = get_post( $new_post );

// Change the post status
$wpdb->update($wpdb->posts, array('post_status'=>'publish'), array('ID' => $post_to_transition->ID));
clean_post_cache($post_to_transition->ID);

// Triggers the notification in BNFW
wp_transition_post_status( "publish", "draft", $post_to_transition );