Setting posts/topics approved to false before calling createPost() doesn't work

Started by horowitz, May 21, 2025, 02:27:50 PM

Previous topic - Next topic

horowitz

Hello,

We are building a function that allows logged in users of our site to post to the forum from other parts of the site using a simpler HTML form which only allows subject and message body plus some other post settings that we want to manually set with our own logic. We are on SMF 2.0.19.

For this purpose I have set up a test forum while writing our custom php code, which uses some of the smf code via includes. We basically use the createPost() function from Subs-Post.php, but we handle the preparation of the form values and set them the way we like based on our own form input. I have looked closely at the Post2() function in Post.php and the createPost() function in Subs-Post.php to figure out how to do this.

Everything works as expected as long as I set $topicOptions['is_approved'] to true and $msgOptions['approved'] to true.

If I set them to false, it does work in the sense that the topic gets marked as "Awaiting approval" in the forum, and the post in the topic also needs mod approval before it's displayed to non mod users in my testforum (it becomes orange and an "Approve" button appears on the post for moderators). So far so good. But if I click on "Approve" on the post, I get taken to the moderator area, but no posts to approve show up. I have tried different combinations of topic "is_approved" and message "approved" set to true or false to no avail (unless they are both true as stated above).

What makes me confused is that I find no function or hook or whatever that performs an action to notify moderators or ensures that it shows up on their moderation dashboard. It SHOULD show up there as long as the columns 'approved' are set to false (or rather 0) in the topic and message tables, no? Are there any other conditions that need to be met?

EDIT: I just found this on line 1977 of Subs-Post.php

$smcFunc['db_insert']('',
'{db_prefix}approval_queue',
array(
'id_msg' => 'int',
),
array(
$msgOptions['id'],
),
array()
);
But that still doesn't explain why the unapproved posts don't show up for my moderator accounts to approve, even though there is an "Approve" button on the posts to click on.

I have turned on "enable post moderation" in the Core Features section of the Admin panel. I have also created a separate user with Global Moderator permissions, and who is also set to be a moderator of the board I'm testing creating topics and posts on.

live627

There may be a seperate section for unapproved topics. I'm not too familiar with the moderation center.

horowitz

I had apparently forgotten to save turning on the "Post Moderation" feature haha. Thanks to you I checked again! Now it works.

There is one issue left: When I approve the posts and topics, the post and/or topic become approved as they should, and display normally in the forum UI afterwards. The only thing that stays is the "There are 1 topics and 1 posts awaiting approval in this board. Click here to view them all. " notification on top of the board. Or rather, it sometimes stays, sometimes disappears and I can't quite figure out why. Any ideas?

Advertisement: