Auto create file and send it via wp_mail()

Can’t help you with the creation of the .doc-file, as i have never done that. But if you manage to get the encoded file into a string, you can work with the WordPress PHP-Mailer instance like this: function send_my_mail_with_attachment($from,$to,$subject,$body,$attachmentstring=””){ global $phpmailer; // (Re)create it, if it’s gone missing if ( ! ( $phpmailer instanceof PHPMailer … Read more

Get ID of first image attached to a post

I assume all your code is wrapped inside the loop? And you should check that a post does indeed have attachments before operating on the $images array: while ( have_posts() ) { the_post(); if ( has_post_thumbnail() ) { the_post_thumbnail( /* No need for “post-thumbnail” argument, it’s the default. */ ); } else { // No … Read more

How to load attachment in media library for current user?

If you want to filter the attachments only at the moment they are being loaded via AJAX, for example when you are setting the post featured image, you can make use of: function filter_get_the_user_attachments( $query ) { $current_user = wp_get_current_user(); if ( !$current_user ) { return; } $current_user_id = $current_user->ID; $query[‘author__in’] = array( $current_user_id ); … Read more

Using delete_attachment to prevent an attachment not working

Updated answer for WordPress 5.5.0+ As of 5.5.0, a new filter has been added to wp_delete_attachment: /** * Filters whether an attachment deletion should take place. * * @since 5.5.0 * * @param bool|null $delete Whether to go forward with deletion. * @param WP_Post $post Post object. * @param bool $force_delete Whether to bypass the … Read more

Proper use of wp_get_attachment_image?

Don’t you need to use get_posts( ‘post_type=attachment’ ) to return the attachment IDs? So, something like: $args = array( ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ => $post->ID ); $attachments = get_posts( $args ); $myimageid = $attachments[0]->ID; wp_get_attachment_image( $myimageid, ‘full’ ); Otherwise, you’re using $post->ID of 1, which isn’t likely to work.

How can I make an attachment page for pdf uploads?

You can use pdf.php or a number of other specially-named template files as described birgire’s answer to show an attachment page specifically for PDFs, or use a generic attachment.php page that includes conditional statements for the type of attachment (like the code in your question does). Potential Conflict with Yoast SEO Plugin Note that attachment … Read more

How do you get the full size url of an attachment image

I think you’re overthinking the system. Unfortunately the nomenclature isn’t helping. The Thumbnail here is the actual image when you use get_the_post_thumbnail_url(). as an example. Say today you uploaded an image called myimage.jpg. That would go, if you’re storing images by date into this directory: /wp-content/uploads/2017/07/myimage.jpg. Now when you call : $featured_img_url = get_the_post_thumbnail_url(‘full’); //(or … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)