AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
Notifications
Clear all

[Solved] Cannot add new topic via Gravity Forms

3 Posts
2 Users
0 Reactions
1,581 Views
Posts: 4
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@apos37)
Active Member
Joined: 2 years ago
[#51273]

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.


2 Replies
Sofy
Posts: 5777
 Sofy
Admin
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@sofy)
Support Team
Joined: 8 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: 8 years ago

Support Team
Posts: 5777
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

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

Share: