I having some troubles with WPF() function.
I want to migrate old forum with a old data base, I need to insert reply in specific topic for all data i need to migrate. i parse my data and as it was mentionnened on this post :
https://wpforo.com/community/how-to-and-troubleshooting-2/is-there-any-way-to-add-new-posts-to-the-forum-programatically/
i try to use this after require_once:
require_once(__DIR__.'/wp-load.php');
if(function_exists('WPF')) {
$reply = array(
'userid' => 3,
'title' => 'RE',
'body' => 'test 2',
'topicid' => 39,
'created' => new \DateTime()
);
$wpf = WPF()->post->add($reply);
exit;
}
i have this result when i launch my script :Â
Error: Call to a member function add() on null
WPF exist cause i test if function exist but the property post is null.
I think this method (init_classes) in wpforo.php has not been call in this script, i try to call it in constructor but there is somes trouble after :
private function init_classes() {
do_action( 'wpforo_before_init_classes' );
$this->activity = new Activity();
$this->api = new API();
$this->feed = new Feed();
$this->form = new Forms();
$this->forum = new Forums();
$this->log = new Logs();
$this->postmeta = new PostMeta();
$this->post = new Posts();
$this->seo = new SEO();
$this->topic = new Topics();
$this->reaction = new Reactions();
$this->bookmark = new Bookmarks();
$this->sbscrb = new Subscriptions();
if( wpforo_is_module_enabled( 'revisions' ) ) $this->revision = new Revisions();
do_action( 'wpforo_after_init_classes' );
}
Any idea about my issue ?
Thanks
You can't access it from the single .php file. You'll need to create a separate plugin. Utilize the wpforo_core_inited hook and then add your custom logic.