Limit Media Library to Given Folder

A solution that works for me is to add a clause to the WordPress query when the media library is being displayed. From browsing my WordPress database I noticed that the full path to wp_posts.post_type=”attachment” is stored in the wp_posts.guid column. add_filter(‘posts_where’, ‘limitMediaLibraryItems_56456’, 10, 2 ); function limitMediaLibraryItems_56456($where, &$wp_query) { global $pagenow, $wpdb; // Do … Read more

wp_generate_attachment_metadata returns empty array

I believe the following is happening here: As @Luke pointed out, wp_insert_attachment() takes an array of post data. The format of the array you are passing to it is not correct. The keys are different. What should be stored as the post_mime_type, is being passed with the key type. Because of this, no mime type … Read more

Modify featured image path to Amazon S3

You can hook into the output and modify the URL there. add_filter( ‘post_thumbnail_html’, ‘my_post_image_html’, 10, 5 ); function my_post_image_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) { $upload_dir = wp_upload_dir(); $base_url = $upload_dir[‘baseurl’]; // Change the default upload directory to AWS Bucket link $AWSBucket=”http://s3.amazonaws.com/bucket”; $html = str_replace($base_url, $AWSBucket, $html); return $html; } Output the image echo … Read more

Change the filename format of saved featured images

There is a filter to use for the array containing the filename that is saved to postmeta but since there are no filters available to change the filename before it is saved you have to manually change it using rename(). function wpse_filter_image_resize_name( $filename ) { $new_name = preg_replace( “/-(?<match>\\d)/ui”, “_$1”, $filename ); if ( rename( … Read more

What might cause a POST to wp-admin/async-upload.php to return JSON >and< HTML?

I had the same issue and did not find any information in my debug output. It worked out, that DOING_AJAX was not defined (I don’t know why). Changing the beginning of async-upload.php from if ( isset( $_REQUEST[‘action’] ) && ‘upload-attachment’ === $_REQUEST[‘action’] ) { define( ‘DOING_AJAX’, true ); } to define( ‘DOING_AJAX’, true ); worked … Read more

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