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

 Sort Search Results by:

Filter by custom fields

Topic prefix

AI Assistant
Notifications
Clear all

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

2 Posts
2 Users
0 Reactions
2,836 Views
Posts: 1
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
(@maxdev)
New Member
Joined: 2 years ago
[#51193]

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: 5774
 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

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
Share: