Notifications
Clear all

[Solved] Cannot add new topic via Gravity Forms

3 Posts
2 Users
0 Likes
506 Views
Posts: 4
Topic starter
(@apos37)
Active Member
Joined: 4 months ago

I'm not expecting any help with integrations, but I'm wondering if there is something blocking me from being able to add a new topic from one of the Gravity Form action hooks. If I use the following code on a test page, I can add a topic just fine, but when I add it to a GF hook, such as 'gform_pre_submission' or 'gform_after_submission', I get an error saying I cannot use add() on NULL. I debug WPF() and it shows the object just fine, so the function is being called, but the 'topic' argument is showing blank. I did the same thing where it worked on a page and the 'topic' argument is showing an empty object instead. Also debugged WPF()->topic and it shows an empty object on the page, but NULL from the GF hook. Any suggestions to get this to work?

$args = [
    'userid'  => 1,
    'title'   => 'New Request from Test',
    'body'    => 'This is a test',
    'forumid' => 22,
    'views'   => 0,
    'type'    => 0,
    'created' => date( 'Y-m-d H:i:s' )
];
$add_topic = WPF()->topic->add( $args);

I also tried working around it by creating my own function that adds new table rows to the database, but it causes issues with being able to delete topics and posts, and some don't show up, so I know there is other stuff I'm missing.

Topic Tags
2 Replies
Sofy
Posts: 4318
 Sofy
Admin
(@sofy)
Support Team
Joined: 6 years ago

I've already sent this topic to the developers. I'll keep you updated once I get a response from them.

1 Reply
Sofy
 Sofy
Admin
(@sofy)
Joined: 6 years ago

Support Team
Posts: 4318

To utilize wpForo objects effectively, ensure they are called in the appropriate sequence. These objects should be invoked before initialization. Therefore, each hook should be executed after the wpforo_core_inited hook.

For example:

add_action( 'wpforo_core_inited', function(){
    //your custom code
    // e.g. 
   // WPF()->topic->add( $topic );
} );