It was the thing in the order of functions, and the check :
if(is_user_logged_in()){
$current_user = wp_get_current_user();
}
else {
$user_id = get_post_field( 'post_author', $post_id );
$current_user = get_userdata($user_id);
}
Related Posts:
- WordPress refuses to send mail, “…your host may have disabled the mail() function”
- WordPress “phpmailer_init” not working for me
- How do I override the Message-ID header of wp_mail function?
- WordPress new user / forgot password emails are broken
- wp_mail function timing out
- Why is my get_post_meta always empty
- Should I use wp_mail or PHP’s mail? [duplicate]
- Mail not sent when I set HTML headers
- Error when requesting password reset email – wp authentication
- Processing a subscription form with POST method?
- Different Webhost and using Google Mail server: Is there a better way than SMTP?
- wp_mail not sending
- Validate emails in array using foreach
- Redirect to another page after submission using wp_mail
- PHP 8, AJAX mail form to function.php doesn’t work
- How to retrieve the sender email with wp_mail()?
- wp_mail file attachment not being placed in upload folder?
- Website needs to be opened for wp_mail to work
- Notify users only on post publish
- Sending a custom form data in email through WP Mail Function
- Pass Variables or Variable Place-Holder from Editor to PHP
- Pass return-path additional parameter in wp_mail
- Send notification email to admin for every new post published
- Different SMTP based on domain
- Get page permalink in contact form
- comment_post (if comment is approved OR $comment_approved === 1) not working?
- Running SMTP Conditionally
- Including user data in “new user notification email”
- Cron not sending wp-mail()
- Email always ends up in spam
- Premature end of script headers: wp-mail.php?
- Adding action item to admin users table and sending email
- Wp_mail doesnt work
- get_post_meta is always empty when I use wp_mail
- wp_mail vs mail functions and header arrays
- Word press – JSPDF – Sending PDF as attachment from wp_mail – Special characters
- wp_mail – send emails after 24 hours from users registration
- Send emails to individual subscribers when CPT post is deleted (trashed)
- Send email with a PDF embedded
- Edit password change email text or disable it
- Send summary email from a form with wp_mail
- Send registration email to all admins
- Code snippet to show current php version inside “At a Glance” box in admin
- parsing nested blocks (in columns, etc) via PHP
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- getting url from variable that calls picture of current page, not working. Only displays everything instead of url
- How to upload WP user avatar on woocommerce account page [closed]
- Use post ID in functions.php file adminside
- How to show childs of certain custom post type in option list?
- Short code template + ajax
- str_replace with the_content is not working
- How do I populate custom field with current user role in Woocommerce [closed]
- WPML best page selector with php
- How to disable send e-mail notification new comments for some posts
- trying to put an active hover to my custom nav category buttons [closed]
- How to edit HTML of my website on WordPress? [closed]
- Redirect first comment (Thanks for comment) with show Autor name and beginning of the comment
- Large WordPress CRON job
- Fixing Deprecated: get_the_author_lastname
- WordPress query undefined offset in loop
- Referencing Images in javascript to display on wordpress page
- Most commented posts by time period (last 12h, last 24h and etc)
- How to: Conditionally Enqueue JS and Stylesheets, for Custom Post Type (Single and Archive Templates)
- Divi change project category slug
- Add meta tags to a custom header
- Ajax filter button display all posts
- Check If Post Was Published More Than 6 Months Ago Using get_the_date
- Where are the src and srcset sizes coming from?
- What is the right way to add PHP code to a certain part of a page
- wp_remote_post empty $_POST
- register_setting & add_settings_error validation issues with multiple fields
- PHP code for displaying WordPress posts in a static page not working
- How to add PHP code in functions.php wordpress
- WordPress hit memory limit but not from the server
- How can I spin up a new website for a registered user automatically?
- How to override url params with rewrite rules vars?
- WordPress wp-admin redirect and exception
- Can I make get_users() query global?
- Using Argument from Function to Re-Direct Visitor (WordPress)
- Use $wpdb or other PHP script method to find/replace in WP database
- Add product to cart for user – WC()->cart->add_to_cart [closed]
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- preg_replace regex problem
- Compare $_POST returned values with term array
- Remove item in Checkout
- email alert for product availability
- How to Update post_modified of all wordpress post
- How to Change CSS Colors from Custom Plugin Settings Page
- malware undetectable by multiple scans
- how to serialize() mysql update data
- Simple WordPress endpoint route doesn’t work
- Correct PHP to output a single result of a Function with SQL Query
- How to relocate paypal button gateway on checkout page in woocommerce
- How to create a field in customize and show that in header.php?
- WordPress shortcode returns the data before
- Passing the name of selected color from the custom component to `render_callback`
- I am receiving a pluggable.php warning sign on my only http:// page
- How to remove the h6 tag for the entry-category Class
- your php installation be missing the MySQL extension WordPress CPANEL [closed]
- Can’t add script immediately after the opening tag on login page?