If you are using that code by Rev Voodoo, you will need to edit that code, not try to hook into WordPress core code. The form in that link submits to itself, and handles its own post processing thus bypassing many core hooks.
Some of the hooks you are trying to use aren’t going to work. I won’t swear to it without investigating more thoroughly but I don’t think I would ever use, or try to use, the submitpost_box
hook for this purpose (It runs while the edit form is being displayed, not when it is submitted). It certainly won’t work in this case because Rev Voodoo’s code never loads the page that uses that hook– wp-admin/edit-form-advanced.php
.
It looks to me like you need to edit the following:
// Do some minor form validation to make sure there is content
if (isset ($_POST['title'])) {
$title = $_POST['title'];
} else {
echo 'Please enter the wine name';
}
I am not sure where you expect to get your teacher name. I am not very comfortable with this but you state that “Only logged in teachers can post”. If you have locked the form adequately then you may be able to do something like this instead of that code:
// Do some minor form validation to make sure there is content
global $currentuser;
get_currentuserinfo();
if (isset($current_user->display_name)) {
$title = $current_user->display_name;
} else {
echo "No user data";
}
Lots of caveats :
- Completely untested
-
Based on your statement that
I want to use that person’s display name as the title of their post
that code completely hijacks the
title. If you want you append or prepend the display name to some
other title that won’t work. - You stand a chance of getting post slugs like
john-smith
,john-smith-2
,john-smith-3
, etc - I am concerned about using
get_currentinfo
because I don’t know how access to your form is controlled. If access to the form is inadequate then any user can post as a teacher.