Linking Gravity Forms to BuddyPress Forums

by | Jan 31, 2023 | WordPress | 0 comments

I was posed with problem: make BuddyPress forum topics from a Gravity Forms form submission. Turning Gravity Form submissions into posts isn’t a big party trick– that is built in. What doesn’t work, is the linkage to a particular forum as a new topic. So: I did some hacking (see the code below).

  • I made a gravity form
  • I have it posting to the post_type for topics
  • I put in a hidden value with the label of “forum_id” and the number for that forum id as the default value for the hidden value
  • I had an existing plugin that was mine. I added the code below to listen for Gravity Form events and then act on the submission.
  • WordPress will do the submission, save the post, then go to this function to act and create linkage between the form submission and a forum.
// publish and associate the form

function sboxr_application_submission( $entry, $form ) {
	if (function_exists('bbp_update_forum')) {
	    //getting post
    	$post = get_post( $entry['post_id'] );

	    //changing post content
	    foreach ($form['fields'] as $key => $values) {
    		if ($values['label'] == 'forum_id') {
    			$post->post_parent = $values['defaultValue'];
    			break;
    		}   
	    }

		$forum_meta = array(
			'forum_id' => $post->post_parent,
			'topic_id' => $post->ID,		
			'comment_status' => 'open'
		);
		$post->comment_status = 'open';	
		$post->post_status = 'publish';

		bbp_update_forum(array('forum_id' => $post->post_parent));
	    //updating post
		wp_update_post($post);
	
		foreach ( $forum_meta as $meta_key => $meta_value ) {
			update_post_meta( $post->ID, '_bbp_' . $meta_key, $meta_value );
		}	
	}
}

// Hook to make the gravity form submission to connect to forum post creation
add_action( 'gform_after_submission_2', 'sboxr_application_submission', 10, 2 );

Five Tips For AI In Content Creation

There’s a lot to consider about the practical aspects of creating content with AI but also the creative collaboration between human intelligence and artificial intelligence.

Understanding CSS Media Queries

CSS media queries are a powerful tool that allow you to apply different styles based on the characteristics of the device or viewport. They enable you to create responsive designs that adapt to different screen sizes, resolutions, and device types (desktop, tablet, mobile, etc.).

Spring into 2024: 30 Great Backlink Sources

Creating backlinks, which are links from one website to another, is a fundamental aspect of search engine optimization (SEO). They act as a "vote of confidence" from one site to another, indicating to search engines that the content is valuable, credible, and useful....

Empowering Legal Advocacy Through Digital Solutions

In an era where digital presence is crucial, Web321 stands at the forefront of offering custom web solutions tailored for groups embarking on legal advocacy, particularly those initiating or involved in class-action lawsuits. Our expertise caters to the unique needs...

What’s the Deal With Quality Content?

What makes content high-quality? When it comes to content marketing, quality goes beyond surface metrics like word count or citations. True quality lies in how well content achieves its purpose and connects with readers. Does it align with marketing goals? Resonate...

Turning Off The AI Bar on Divi

Divi (the theme system from Elegant Themes) has added an AI tool. Some people don’t like it. With the most recent copy of Divi, the element can be switched off.

Performance Improvements That Can Speed Up Your Website

Let’s explore how to achieve some WordPress performance improvements to ensure your website is as swift while keeping any of the pizazz delivered by Javascript and CSS, keeping your audience captivated and Google happy. Let’s supercharge your WordPress website!

7 WordPress Maintenance Services in 2023

If you are tired of spending hours on mundane upkeep tasks or need expert help improving your WordPress website, a maintenance service can help you take the hassle out of running your site.

Kite Dish.com Acquired by Web321

We are proud to pick up the mantle of Kite Dish. Back in the day, they provided WordPress Maintenance. As they said it, back then: Our service provides you a peace of mind with a secure, regularly backed up, bug-free and proactively updated site so you can concentrate...