SMF 2.0 insert post via function API

I decided to create an automated forum poster for SMF forums. Found description  of their function reference. Function was located at Subs-Post.php

Function name:  createPost

Function description
Inserts a new post into the database with the appropriate options.

Function syntax
bool createPost (array &$msgOptionsarray &$topicOptionsarray &$posterOptions);

I will not repeat their description, here is a direct link.

However, I’ve met unexpected problem, and decided to post the solution here. I hope I will save some time for somebody this way. The problem I’ve met was fatal error:

Fatal error: Function name must be a string in …/forum/Sources/Subs-Post.php on line 1811.

The problem detected was, that variable $smcFunc vas empty in Subs-Post.php. As far as I called the function createPost() directly from my forum poster, I’ve traced this variable, and solution is as follows:

  • require_once(dirname(__FILE__) . ‘/Settings.php’);     this step is NOT a solution,  it just loads some variables,  mainly database.
  • require_once(dirname(__FILE__) . ‘/SSI.php’);   this IS a solution.  $smcFunc is defined here.
  • removed  define(‘SMF’, true);    this definition is described in SSI.php, so I do not need to duplicate it.  This definition is REQUIRED for separately included files to load.
  • require_once(dirname(__FILE__) . ‘/Sources/Subs-Post.php’); this is the next lines of my poster, I need this file, because I need the function createPost();
This way I’ve got rid off that fatal error.
This entry was posted in PHP tips. Bookmark the permalink.

Leave a Reply