How to protect media directory with .htaccess?

# Only allow access to this directory if they are coming from your domain; excluding you, your server, Google and any other IPs RewriteEngine On RewriteCond %{REMOTE_ADDR} !^(xxx\.xxx\.xxx\.xxx|xxx\.xxx\xxx\.xxx|66\.249\.) RewriteCond %{HTTP_HOST} !^(127\.0\.0\.0|localhost) [NC] RewriteCond %{HTTP_REFERER} !^https?://(.+\.)?yourdomain\.com/ [NC] RewriteRule .* http://yourdomain.com/ [L] That should help, I think

Close the media-upload thickbox right after upload is finished?

This was solved as simply as: Hooking a custom .js script to the media-upload thickbox, so that it runs inside the iFrame: function admin_styles_scripts_media_upload() { wp_register_script(‘mediajs’, get_template_directory_uri().’/js/button.js’, array(‘jquery’), true); wp_enqueue_script(‘mediajs’); } add_action(‘admin_print_scripts-media-upload-popup’,’admin_styles_scripts_media_upload’); ?> Use the script to replace the default Save button with a custom one, and call self.parent.tb_remove from that: jQuery(document).ready(function() { jQuery(‘<a href=”#” … Read more

Bug when uploading pictures with international characters?

That is a bit odd, and I can’t reproduce your error. Perhaps it has something to do with differnt character encodings of the filename/filesystem you are uploading from or to. When handling file uploads WordPress sanitizes the file name to remove spaces and some other unwanted characters. This sanitizing is performed by sanitize_file_name when the … Read more

Media handle sideload not working

For those having similar problem, I cleared web-server’s /tmp partition being filled with temp files. The root cause was actually that my hosting provider sets the /tmp partition to be 128MB when on their VPS, which is far too small for the size of uploads that I want to be able to do.

Add select field to media uploader that adds a class to the image

To apply the class you need a custom function to do something with the value of your setting. To make sure the selected stays selected use the WP selected() function $form_fields[‘image-type’][‘html’] = “<select name=”attachments[{$post->ID}][profile_image_select]”>”; $form_fields[‘image-type’][‘html’] .= ‘<option ‘.selected(get_post_meta($post->ID, “_profile_image_select”, true), ‘default’,false).’ value=”‘ . $normal_image . ‘”>Normal Image</option>’; $form_fields[‘image-type’][‘html’] .= ‘<option ‘.selected(get_post_meta($post->ID, “_profile_image_select”, true), ‘default’,false).’ value=”‘ … Read more

upload files dynamically to user folders

You can grab a WP_User instance with get_user_by() – Codex documents that pretty well. add_filter( ‘upload_dir’, ‘userLoginUploadDir’ ); function userLoginUploadDir( $args ) { // Assuming that your forms user login (search? autocomplete? AJAX-ified? foo?) is named // name=”user_login” id=”user_login” $userLogin = esc_attr( $_GET[‘user_login’] ); $user = get_user_by( ‘login’, $userLogin ); $upload_dir = wp_upload_dir(); return array_merge( … Read more

How to side load an image from a service

Short answer, you don’t. Functions like sideload are for importing images into WordPress itself and using all the normal media library stuff. For images on an external service, use normal img tags. If you want to copy an image from a URL, you sideload it. Not otherwise.

What error logs can I check to see why plugin updates are failing?

In wp-config.php, set the following (if not already set): define( ‘WP_DEBUG’, true ); define( ‘WP_DEBUG_LOG’, true ); define( ‘WP_DEBUG_DISPLAY’, false ); @ini_set( ‘display_errors’, 0 ); This will make sure that on the site no error is shown, however, WordPress will log all errors in debug.log file inside the /wp-content/ directory. NOTE: You must insert this … Read more

Allowing .exe uploads (old WPSE posts no longer work)

WordPress provide a hook to change the default mime types, like your hint in the question. The follow small code source demonstrated the change to allow a exe-file. add_filter( ‘upload_mimes’, ‘fb_enable_extended_upload’ ); function fb_enable_extended_upload ( array $mime_types = [] ) { $mime_types[ ‘exe’ ] = ‘application/exe’; return $mime_types; } It is not necessary to change … Read more

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