Display Author name with PHP (Selfmade PlugIn)
-
Hello to all,
I have a problem for which I need help, because I just can not find a solution myself.
I have taken over a site where a selfmade plugin was created by someone before..
Using the default plug-in „Contact Form 7“, people can create posts on the page. ( https://gyazo.com/c8b20adecacd90fb9bfe72ad2138a980 )
About the self-created plug-in „Contact Form 7 extender“, the post is generated in the background via a PHP code. (https://gyazo.com/115a6c7c9afafd2970b66fd421ca76a3)This is how it should work:
If a user is not logged in, the author becomes „Hyperspace_Bot“.
If a user is logged in, the Author name of the user is displayed.Now the problem:
When a user who is logged in creates a post via the contact form, no Author is displayed….
(https://gyazo.com/b51653a1c5fc08b875a50b926c7565d3)
(https://gyazo.com/54e4067ecf1227831898a79e1577affa)
As you can see on the screenshots again, there is no author entered. Currently I always have to enter them manually afterwards.Here is the important part of the code of the plug-in:
add_action('wpcf7_before_send_mail', 'createPostData' ); function createPostData() { //get user id //$user = get_userdatabylogin('myusername'); //$user = get_user_by('login', $user_login); //$udi = $user->ID; get_currentuserinfo(); if ($_POST['aut'] == '') { // Create post object $my_post = array( 'post_title' => $_POST['title'], 'post_content' => $_POST['Description'], 'post_status' => 'pending', 'post_author' => 3, 'post_category' => array($_POST['postcategory']) ); } else { $my_post = array( 'post_title' => $_POST['title'], 'post_content' => $_POST['Description'], 'post_status' => 'publish', //'post_author' => $user, 'post_author' => $user_ID, 'post_category' => array($_POST['postcategory']) ); }
The problem is with ‚post_author‘ => $User_ID in the second part I think…. I’ve already tried different ways with get_current_user_id() or $author_id = get_the_author_meta( ‚ID‘ ), but can’t find a solution.
If someone has an idea, I would be very grateful!
Thanks a lot in advance.
Best regards
Fabian- Dieses Thema wurde geändert vor 2 Jahren, 2 Monaten von .
- Dieses Thema wurde geändert vor 2 Jahren, 2 Monaten von .
Die Seite, für die ich Hilfe brauche: [Anmelden, um den Link zu sehen]
- Das Thema „Display Author name with PHP (Selfmade PlugIn)“ ist für neue Antworten geschlossen.