Skip to main content Skip to navigation Skip to footer

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.

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:

// 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 );

Privacy Overview

This website uses cookies so that it can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to this website and helping employees to understand which sections of the website you find most interesting and useful.

Strictly Necessary Cookies

This website uses the Stripe Payment Processor. Cookies from Stripe are required in order for this website to provide eCommerce functions, such as to accept payments.

This website uses YouTube to host and display videos relating to the operation of this plugin and forms part of the documentation. Use of cookies from YouTube is required in order to fully document or explain elements of a product.

PHPSESSID - This cookie is native to PHP applications. The cookie is used to store and identify a users' unique session ID for the purpose of managing a user's session on the website. The cookie is a session cookies and is deleted when all the browser windows are closed.