Remove fields on media uploader for custom page type – not working for “From Computer” or “From Url” tabs?

Version 1 Deals with filtering based on Post ID *From Computer* tab we need to retrieve the $attachment_parent_id: add_filter(‘attachment_fields_to_edit’, ‘wpse_53600_remove_media_upload_fields’, 10000, 2); function wpse_53600_remove_media_upload_fields( $form_fields, $post ) { $our_page_id = 4; $post_id = !empty( $_GET[‘post_id’] ) ? (int) $_GET[‘post_id’] : 0; $attachment_parent_id = !empty($post->post_parent) ? $post->post_parent : 0; if( $post_id == $our_page_id || $attachment_parent_id == … Read more

Group images in media library

Attachments itself same as posts… so you can think on giving tham meta_values or adding taxonomies to tham. as for me i always used first method… this is a simple example of how this functioonality works… add_filter(“attachment_fields_to_edit”, “afields_to_edit”, 10, 2); add_filter(“attachment_fields_to_save”, “afields_to_save”, 10, 2); function afields_to_save($post, $attachment){ $parentPost = get_post($post[‘post_parent’]); /************************************************************* // Roles *************************************************************/ if … Read more

Show how many images are attached to a post/page on compose page

add_action( ‘add_meta_boxes’, ‘attached_images_meta’ ); function attached_images_meta() { $screens = array( ‘post’, ‘page’ ); //add more in here as you see fit foreach ($screens as $screen) { add_meta_box( ‘attached_images_meta_box’, //this is the id of the box ‘Attached Images’, //this is the title ‘attached_images_meta_box’, //the callback $screen, //the post type ‘side’ //the placement ); } } function … Read more

How to save media files under custom folder without changing wp-config.php or changing media settings

Here is simple function to create your own sub directory for every upload. function kv_custom_image_dir( $pathdata ) { $subdir=”/uploads_img”.$pathdata[‘subdir’]; $pathdata[‘path’] = str_replace($pathdata[‘subdir’], $subdir, $pathdata[‘path’]); $pathdata[‘url’] = str_replace($pathdata[‘subdir’], $subdir, $pathdata[‘url’]); $pathdata[‘subdir’] = str_replace($pathdata[‘subdir’], $subdir, $pathdata[‘subdir’]); return $pathdata; } add_filter( ‘upload_dir’, ‘kv_custom_image_dir’ ); From my above code, I changed my images folder as uploads_img, you can change … Read more

How to link to “most recent” document in the Media Library?

You could search the latest attachments like my example below. I searches for the string “newsletter”, and the first time it pops up in a filename, it writes a link. I’ve tried to make it easy to understand. $attachments = get_posts( array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => 20, ‘post_status’ => null, ‘post_mime_type’ => ‘application/pdf,application/msword’ ) … Read more

How to get media objects

Have you tried to use get_children() function? Edit: All media attached to any post is treated as children of it. The function wp_get_attachment_image() will only return images. With the function get_children() you’ll be able to get all the media, images or anything else. In the above link, you can find some examples.

wordpress media library shows empty images

Plugins such as Search and Replace can help you to properly fix the URLs in your database. Likewise, consider using backup-and-migration plugins such as BackupBuddy (paid) or Duplicator (free) to properly and more easily move your site (while automatically handling the above search-and-replace operation).

How to upload unknown file type?

You can use this function as you mentioned and you need to learn your file extensions mime type (in example i add svg and xcf upload ability to wordpress) add_filter(‘upload_mimes’, ‘ability_to_upload’); function ability_to_upload($mimes = array()) { $mimes[‘svg’] = ‘image/svg+xml’; $mimes[‘xcf’] = ‘image/xcf’; return $mimes; } Here is a link for mime types list and file … Read more