Home › Toolset Professional Support › [Resolved] BBpress Post On CRED Submit
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - | - | 9:00 – 13:00 |
14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - | - | 14:00 – 18:00 |
Supporter timezone: Africa/Casablanca (GMT+01:00)
Tagged: Content-submission forms, CRED API, Toolset Forms
Related documentation:
This topic contains 16 replies, has 4 voices.
Last updated by JoshuaJ301 4 years, 1 month ago.
Assisted by: Jamal.
Tell us what you are trying to do?
I'm trying to get my code to work with a CRED submit to automatically submit a BBpress post. I think I'm fundamentally missing something in my code or some lack of understanding on how it works. I want the BBpress post to contain some fields with information about the submitted download file. Also, I'm not sure if it's possible to have the BBpress link that's created to be automatically posted in the custom post. I'm trying to create a download system where my users submit a file and it automatically creates a "support topic" in BBpress with a link back to the file in the bbpress post as well as a link from the post to the support topic.
Ths is my code thus far:
//**New BBPress Topic on CRED Submit**// add_action('cred_save_data', 'my_save_data_action',10,2); function my_save_data_action($post_id, $form_data) { // change this 12 to the actual id of your form if ($form_data['id']==222) { // You may need to modify the post author and post categories for your needs $my_post = array( 'post_parent' => 231, // forum ID 'post_type' => 'downloads', 'post_author' => bbp_get_current_user_id(), 'post_status' => bbp_get_public_status_id(), 'post_title' => get_post_meta($post_id, 'wpcf-file-name', true), 'post_status' => 'publish', 'post_content' => get_post_meta($post_id, 'wpcf-about-this-file', true), ); // Insert the post into BBpress bbp_insert_topic( $my_post ); } }
Is there any documentation that you are following?
NA
Is there a similar example that we can see?
NA
What is the link to your site? beta.iwebnow.net
Hello. Thank you for contacting the Toolset support.
The code you shared is a custom code but let me try to check whats going on with the code you shared.
Can you please share problem URL where I can see the form as well as access details and tell me where exactly you added the code you shared with your initial post?
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Thank you for sharing access details but can you please share the link of the page/post where you added the Toolset form?
Oh Sorry, I forgot to add this in my last post
The CRED for is here
hidden link
Hello Joshua, Minesh is on vacation, so I'll continue with you on this ticket.
Please consider that I am not familiar with bbPress, but I'll do my best to help.
First of all, I see that you are entering the status two times, on lines 13 and 15, it will need to be corrected.
Then, bbPress was deactivated, which makes me suspect that the code will break because bbPress functions won't be available.
I tried to activate bbPress, but it does not complete. Check this screenshot hidden link
I tried to login with FTP to check the debug.log file but the credentials are not working for me.
Please make sure that the bbPress plugin is active. Turn PHP debugging to spot the errors that prevent it from activation.
Once bbPress ready, let me know where should I check if a forum topic is created? I'll try to see what's going on.
Hi Jamal,
My apologies. I am using Buddyboss platform which has bbpress as part of it's core. It is activated. The original BBpress was installed so that I could migrate Invision Power Services forum into BBpress so that the Buddyboss platform could use it.
The forum is active already - hidden link
I did double check that FTP account and recreated it and tested it and it did work. I might have set it up incorrectly. Sorry about that.
Thank you for this explanation.
I would like to ask more questions to understand it better:
- I imagine that bbPress has a screen under its menu. Does Buddyboss have it? How do you see the available forum topics in the backend? Can you share a URL where I can see the created forum topics?
- How can we check if a topic is created or not? How can we create a new topic from the backend?
Hey Jamal,
Yes of course. So very sorry for not explaining this up front. I forget sometimes when I'm using Buddyboss that it's a little different than the traditional BBpress.
It's basically the same as BBpress they're just included the link under "Buddyboss" in the backend. I've included an image so you can see where it is located.
To create a new topic from the backend you would just click on the "Discussions" link in that image at the top and there is a button to create a "New Discussion"
Currently I set up a "Test Forum" which is forum ID 3967, to test my cred code.
I've also set up my Toolset "Downloads" area at beta.iwebnow.net/downloads/
I checked your custom code and the BuddyBoss documentation hidden link
The code seems correct to me, and it does create a new topic. But for whatever reason, the created topic is not assigned to the parent forum. I have also tried "forum_id" instead of "post_parent", but when I try to get the forum_id from the created topic_id, I get 0.
Please reach out to the BuddyBoss support team and ask for help to understand why is the newly created topic does not get the correct parent forum_id.
Check the last part of the code, that I commented out. If you uncomment that part, you will see that the topic is being created, but its parent forum_id is equal to 0.
I am afraid, there is nothing else I can do here to help unless we know what's going on with the BuddyBoss/BBpress API. I'll keep this ticket open, waiting for your feedback, until you check with the BuddyBoss team.
Thanks Jamal.
I will do that and see what I can do to get the topic id.
Just an update - I was able to get this to post to the correct form when it is submitted. However; it doesn't pass the form information to the BBpress topic. It's just showing "Add New Download" as the BBpress Topic and for the content it's showing the shortcode
[cred-form form="form-for-downloads" ]
//**New BBPress Topic When CRED Submit **// add_action('cred_save_data', 'my_save_data_action',10,2); function my_save_data_action ($post_id, $form_data) { //set the forum ID that the topic will be saved to $forum_ID = '3967' ; if (!function_exists('bbp_insert_topic')) { require_once '/includes/topics/functions.php'; } // change this 12 to the actual id of your form if ( $form_data['id'] == 222) { //getting post $post_form = get_post($entry['post_id']) ; $title = $post_form->post_title; $content = $post_form->post_content; // The topic data. $topic_data = bbp_parse_args( $topic_data, array( 'post_parent' => $forum_ID, // forum ID 'post_status' => bbp_get_public_status_id(), 'post_type' => bbp_get_topic_post_type(), 'post_author' => bbp_get_current_user_id(), 'post_password' => '', 'post_content' => $content, 'post_title' => $title, 'comment_status' => 'open', 'menu_order' => 0, ), 'insert_topic' ); // The topic meta. $topic_meta = bbp_parse_args( $topic_meta, array( 'author_ip' => bbp_current_author_ip(), 'forum_id' => $forum_ID, 'topic_id' => $topic_id, 'voice_count' => 1, 'reply_count' => 0, 'reply_count_hidden' => 0, 'last_reply_id' => 0, 'last_active_id' => $topic_id, 'last_active_time' => get_post_field( 'post_date', $topic_id, 'db' ), ), 'insert_topic_meta' ); $post_id = bbp_insert_topic($topic_data, $topic_meta); } }
AH, I'm an idiot!
I forgot to set the title fields!
Is there a way I can set multiple form fields into the 'post_content' code? I want to include the file Image as well as the "about this file" information?
//**New BBPress Topic When CRED Submit **// add_action('cred_save_data', 'my_save_data_action',10,2); function my_save_data_action ($post_id, $form_data) { //set the forum ID that the topic will be saved to $forum_ID = '3967' ; if (!function_exists('bbp_insert_topic')) { require_once '/includes/topics/functions.php'; } // change this 12 to the actual id of your form if ( $form_data['id'] == 222) { //getting post $post_form = get_post($entry['post_id']) ; $title = $post_form->post_title; $content = $post_form->post_content; // The topic data. $topic_data = bbp_parse_args( $topic_data, array( 'post_parent' => $forum_ID, // forum ID 'post_status' => bbp_get_public_status_id(), 'post_type' => bbp_get_topic_post_type(), 'post_author' => bbp_get_current_user_id(), 'post_password' => '', 'post_content' => get_post_meta($post_id, 'wpcf-about-this-file', true), 'post_title' => get_post_meta($post_id, 'wpcf-file-name', true), 'comment_status' => 'open', 'menu_order' => 0, ), 'insert_topic' ); // The topic meta. $topic_meta = bbp_parse_args( $topic_meta, array( 'author_ip' => bbp_current_author_ip(), 'forum_id' => $forum_ID, 'topic_id' => $topic_id, 'voice_count' => 1, 'reply_count' => 0, 'reply_count_hidden' => 0, 'last_reply_id' => 0, 'last_active_id' => $topic_id, 'last_active_time' => get_post_field( 'post_date', $topic_id, 'db' ), ), 'insert_topic_meta' ); $post_id = bbp_insert_topic($topic_data, $topic_meta); } }
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Sorry for the delay getting back to you, both Minesh and Jamal are off, if neither of them return soon I'll look through this in more detail myself and get back to you.
Thanks Nigel.
It seems like I've got the code to work on the test site. I was curious how I can customize the "post_content" part of the code to include the "downloads" image as well as "about" fields from Toolset.
One other question. Is there any way to tell the function
if x field = null then do not create new topic
I want to create a "does this item have a support topic" check box and that will trigger the function to post the topic other wise it doesn't need a topic. Sorry for all the questions I'm new at learning php.
On your reply here https://toolset.com/forums/topic/bbpress-post-on-cred-submit/#post-1836899
You can add the condition before line 45. Note that Toolset checkboxes can either store(1, 0, or nothing) depending on how you configure the field, check this screenshot hidden link
But, if the checkbox is checked, 1 will be stored on the database, so a code like the following should work for you, assuming that the checkbox slug is "has-support-topic":
$has_support_topic = get_post_meta($post_id, 'wpcf-has-support-topic', true); if ( $has_support_topic == 1 ){ // Now create the topic $post_id = bbp_insert_topic($topic_data, $topic_meta); }
However, for support rules, we are able to handle only one issue at a time. This helps us to bring you a better service and also helps other users to find all the information here exposed. For that reason I have to kindly ask you to open a new thread if you need further assistance, you can assign it directly to me. In that way, you don't have to wait and we can continue working on it.