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

Select image sizes you want to be uploaded

If I am not mistaken, WordPress just creates these sizes. The only thing you can say is which image you want to pick of these sizes. You can use this piece of code to make the sizes appear inside of the dropdown. Make sure to place this inside the functions.php after adding the image_sizes. function … Read more

Intercept request to /wp-content/uploads/random.file

I just ran a test where I uploaded an image to media library, then renamed my root index.php file to break WordPress, but the image I uploaded was still available by accessing it directly with its wp-content/uploads/… URL. There are no .htaccess files in wp-content or uploads either, which means that, barring any plugins that … Read more

Gravity Forms – Repeatable “File Upload” field using “gform_column_input_content” filter [closed]

The following provides you with a file upload: add_filter(“gform_column_input_content_21_9_3”, “change_column3_content”, 10, 6); function change_column3_content($input, $input_info, $field, $text, $value, $form_id) { $input_field_name=”input_” . $field[“id”] . ‘[]’; $tabindex = GFCommon::get_tabindex(); $new_input=”<input type=”file” name=”” . $input_field_name . ‘” ‘ . $tabindex . ‘ class=”YOUR-CSS-CLASSES” />’; return $new_input; } But what does ‘repeatable’ mean in this context? Do you … Read more

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

Media upload – choose only one file

WordPress contains 2 media up-loaders. The Flash uploader allows the selection of multiple files while the browser uploader only allows 1 file at a time. To disable the Flash uploader add the following filter to functions.php add_filter(‘flash_uploader’, create_function(‘$flash’, ‘return false;’)); EDIT After further investigation it’s probably not a great idea to use create_function. A beter … Read more

White-list file types for media upload

You can hook the upload_mimes filter to accomplish this: add_filter(‘upload_mimes’, ‘wpse_43657_upload_mimes’); function wpse_43657_upload_mimes($mime_types){ $mime_types[‘rwp’] = ‘application/octet-stream’; return $mime_types; }

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