How to allow specific extensions and file size to wp_mail attachment?

Add the following condition before the file upload functionality – $allowedExts = array(“pdf”, “jpg”, “png”); $temp = explode(“.”, $_FILES[“attachment”][“name”]); $extension = end($temp); if ((($_FILES[“file”][“type”] == “image/pdf”) || ($_FILES[“file”][“type”] == “image/jpg”) || ($_FILES[“file”][“type”] == “image/png”)) && ($_FILES[“file”][“size”] < 1000000) && in_array($extension, $allowedExts)) { //your file upload code and other stuffs } else { echo “Invalid file”; … Read more

How can I add a fifth option to the alignment picker?

You mentioned using the class in your comment. You could try just adding max-width:100% to the css from the link you provided. Or use jQuery: $(document).ready(function(){ $(‘img.fulljust’).each(function(){ if($(this).width() > 300){ $(this).css({ ‘width’ : ‘100vw’; ‘position’: ‘relative’; ‘left’: ‘50%’; ‘right’: ‘50%’; ‘margin-left’: ‘-50vw’; ‘margin-right’: ‘-50vw’; }); } }); }); EDIT: I realized I didn’t answer your … Read more

Check if image exists before uploading with media_sideload_image()

I wonder if you’re looking for the core attachment_url_to_postid() function that uses: $sql = $wpdb->prepare( “SELECT post_id FROM $wpdb->postmeta WHERE meta_key = ‘_wp_attached_file’ AND meta_value = %s”, $path ); $post_id = $wpdb->get_var( $sql ); Note the extra meta key _wp_attached_file check compared to your current snippet. If you need to check if an image url … Read more

Automatically delete attachments and posts [closed]

You can solve your problem with a WordPress Cron Job. I wrote this code and cron scheduler. Also i tested this code on my localhost. If you add this code to your theme’s functions.php you can solve your problem. Cron job and function will work every day and search old posts and their attachments for … Read more

Adding attachment file name to email link

You can get the original attachment filename via wp_get_attachment_url: echo basename( wp_get_attachment_url( $post->ID ) ); or in the form of the example you provided: <a href=”https://wordpress.stackexchange.com/questions/91547/mailto:[email protected]?Subject=Image: <?php the_title(); ?> – <?php echo basename( wp_get_attachment_url( $post->ID ) ); ?>”>Get in touch about this image</a>

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