Add suffix to filename of uploaded images

I did it in a different way. I just had to update the code from Gerasimos Tsiamalos Retina Plugin to WordPress 3.5., using image editor instead of image resize. This is how it looks like: function nothing_image_make_retina_size($file, $width, $height, $crop=false) { if ( $width || $height ) { $resized_file = wp_get_image_editor($file); if ( ! is_wp_error( … Read more

How to add a rel attribute to images that contains their categories?

This should work for the rel attribute: /** * Create a rel attribute from the image categories * * @see http://wordpress.stackexchange.com/a/158024/26350 */ add_filter( ‘get_image_tag’, function( $html, $id ) { $rel = array(); foreach( (array) get_the_category( $id ) as $cat ) { $rel[] = $cat->slug; } return str_ireplace( ‘<img ‘, sprintf( ‘<img rel=”%s” ‘, join( ‘ … Read more

How can I get a different image size, if all I have is the link?

I decided to use this, which is based on @AndresYanez’s answer: function get_image_id_by_link($link) { global $wpdb; $link = preg_replace(‘/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i’, ”, $link); return $wpdb->get_var(“SELECT ID FROM {$wpdb->posts} WHERE BINARY guid=’$link'”); } This is much more succinct (since it doesn’t jump through the hoops of first removing the extension and then adding it back in), and is … Read more

attachment url rewrite

Actually, you can always just use a query parameter, even if you have the “pretty” permalinks enabled. So instead of /category/sub-category/article.html/attachment/image you can go to /?attachment=image. The only case when this “breaks down” is when you go to /category/sub-category/article.html?attachment=image, because WordPress gets confused: it tries to query for a post and an attachment at the … Read more

Rename attachments during upload

You can try to replace $arr[‘name’] = $post_slug . ‘-‘ . $random_number . ‘.jpg’; with $arr[‘name’] = $post_slug . ‘-‘ . $arr[‘name’]; to get the file format [post_slug]-[original_filename].ext. Update: Here is an example of the $arr structure for an image with the filename car.png : Array ( [name] => car.png [type] => image/png [tmp_name] => … Read more

Upload images and attachments from frontend form

I mentioned in a comment how it’s important to debug your code. Here’s why: The images are added first. In the image adding section, you’re running this line of code: $_FILES = array(“moreimages” => $image); Then when you get to your routine that adds the files, you start with this: $files = $_FILES[‘morefiles’]; Can you … Read more

Get post embedded image caption

If I understood correctly, you are trying to add, to every image embedded in a post gallery, a custom rel attribute and a title attribute based on the attachment caption. Instead of parsing the content, you can try to modify the anchor that wraps the images using the ‘wp_get_attachment_link’ filter. <?php function wpse221533_add_caption_title_to_content_gallery_image_attachments( $markup, $id, … Read more

Is there a plugin that allows a user of your site to get an email from you with an attachment?

you can use wp_mail( $to, $subject, $message, $headers, $attachments ); to send emails with attachments. So all you need is a simple form <form name=”email-att” id=”email-att” method=”POST” action=””> Enter your emial: <br /> <input type=”text” name=”email” id=”email”/><br /> <input type=”hidden” name=”action” value=”email-att”/><br /> <input type=”submit” name=”submit” value=”submit” id=”submit”/> </form> and to process it <?php if … Read more

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