Support Forum

Post to forum + detect if they have a post in the forum (If they do, use this post and reply instead of post to forum)

RY Ryan
Ryan
Member

Hey All,

I’m not quite sure how this would work but I’m trying to call the api from a standalone page and do the following:

Check if current user has posted in subforum “autoposts”

If they haven’t got a post in that subforum with the title: “Username’s Set” then it needs to create a post with that title and post the contents of $postcontents to it.

If they have got a post in that subforum with the title: “Username’s Set” then it should reply to that topic with the replies post content being $postcontents.

That’s it, pretty simple but I can’t work it out, I’ve found sph_post_create and I’ve had a look under spFunctions.php but nothing helps :/

Any ideas?

3 Answers

New Answer

MP Mr Papa
Mr Papa
Member

not exactly sure what you want to do, but lets try breaking into pieces and build up to it…  so first, how to check if user has posted in forum ‘autoposts’…

no api per se, but you can query the db:

sp_forum_api_support(); # lets load some more api stuff
global $spThisUser; # access current user

$data = spdb_query('SELECT * FROM '.SFPOSTS." WHERE user_id=$spThisUser->ID AND forum_id=x"); # replace x with appropriate forum id
if ($data) {
    # user has posted in forum
} else {
    # user has not posted in forum
}

and let me suggest some reading for creating a forum post…  you will want to use our post class..  just instantiate it, fill it with data and submit…

Take a look at the our sp-post.php file in simple-press/forum/library…  will give you example of using the class… or for more focused, smaller example, see

post multiple plugin, file post-multiple/library/sp-post-multiple-components.php around line 104

blog linking plugin, file blog-linking/library/sp-linking-blog.php around line 108

for a couple of examples of plugins we use the post class… there are more too if you search for “= new spPost”

so get started and come on back with any more questions…

RY Ryan
Ryan
Member

Cheers Mr Papa,

That query should help me do what I want to do :)

Is it possible to post to a sub-forum via the api even if they don’t have access to the forum, for a logging purpose?

MP Mr Papa
Mr Papa
Member

requirements checks for pemissions will be in force… you can bypass those by using hooks…  or posting as an admin, then changing the poster after creating it…