What’s the easiest way to close comments on media/attachments?

This ought to do it: function wpse15750_comment_check( $id ){ if( get_post_type( $id ) == ‘attachment’ ) exit; } add_action( ‘pre_comment_on_post’, ‘wpse15750_comment_check’ ); EDIT Ignore the above. That will stop new comments, but to do what you want, this is much better: function wpse15750_comments_closed( $open, $id ){ if( get_post_type( $id ) == ‘attachment’ ) return false; … 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

Upload specific images to specific folder

In your answer you said that desired path is something like wp-content\uploads\state-name\destination\ where state-name is a taxonomy term and destination is the slug of one destination CPT. Last thing is not clear from your question, but it seems so, let me know if I’m wrong). So, I suggest you this workflow: Add a destination post … Read more

media_handle_upload for local files?

You want media_handle_sideload() Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload(). // Array similar to a $_FILES upload array. $file_array = array( ‘name’ => ‘filename.jpg’, ‘tmp_name’ => ‘path/to/filename.jpg’, ); // Post ID to attach upload to, 0 for none. $post_id = 0; $attachment_id = media_handle_sideload( $file_array, $post_id … Read more

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