Issue on Running Image upload on WP Metabox Custom Image Loader

I had the same error because I forgot to add: wp_enqueue_media(); Then I found this how to and solved the problem like this: 1: You have to enqueue WP JavaScript library for media and your own JS file: public function enqueue_scripts() { //WP library wp_enqueue_media(); //Your JS file wp_register_script(‘name-of-your-script’, plugin_dir_url( __FILE__ ) . ‘js/path-to-your.js’, array( … Read more

WordPress site stuck at 1MB for max file size

I had the very same problem. None of googled articles suggesting trivial solutions (like “resize image”, “wait a bit”) helped. Symptoms: media uploading works perfectly, but only for some files (larger than 1Mb) the “HTTP error” occurs. But when I tried to check my web server logs, everything became clear in one second. I suppose … Read more

Post Specific Uploader

Check if the argument is present, and if it isn’t return the default value: if(!isset($_REQUEST[‘post_id’])) return $upload; // cast it to integer to avoid problems $id = (int)$_REQUEST[‘post_id’]; …

How Can I pass an image file to wp_handle_upload?

wp_handle_upload() is made to handle, well, uploads. It expects upload-related inputs. To “upload” image from remote URL there is media_sideload_image(). Since you actually don’t specify type of your file, you might need to tinker some yourself, using this function as an example.

Accessing Media/Files outside the_content

Try the following code: $args = array( ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ => $post->ID ); $attachments = get_posts( $args ); if ($attachments) { foreach ( $attachments as $attachment) { setup_postdata($attachment); the_title(); the_attachment_link($attachment->ID, false); the_excerpt(); } }

Add file extension to temporary file

The problem: When you download an image with an extension, for example jsbach_image.jpg, it will look like this in the temp directory: /tmp/jsbach.tmp but when you download an image without an extension, for example mozart_image, you will get: /tmp/mozart But the latter one will not pass the filetype- and extension tests in the wp_handle_sideload() function, … Read more

post_id missing from the wp-admin file upload request

Ok this seems to have fixed it: function wp_plupload_include_attachment_id( $params ) { global $post_ID; if ( isset( $post_ID ) ) $params[‘post_id’] = (int) $post_ID; return $params; } add_filter( ‘plupload_default_params’, ‘wp_plupload_include_attachment_id’ ); This preprocesses the uploader $params and makes sure the post_id is included. Taken from here: https://core.trac.wordpress.org/attachment/ticket/22085/media.php.patch

Incremental number handling on duplicate file names

The number is added in wp_unique_filename() in wp-includes/functions.php. You can prevent it by hooking into ‘sanitize_file_name’ and setting another file name. You can find such functions and filters by following the code with your IDE. Most IDEs make functions clickable so you can go from their call to their declaration. Here is an example from … Read more

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