Can't use the funct...
 
Notifications
Clear all

Can't use the function WPF()->post->add($reply)

2 Posts
2 Users
0 Reactions
460 Views
Posts: 1
Topic starter
(@maxdev)
New Member
Joined: 11 months ago

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

1 Reply
Sofy
Posts: 4900
 Sofy
Admin
(@sofy)
Support Team
Joined: 7 years ago

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.

Reply