Applying automatic link class to images embedded to posts

You can run a filter on image_send_to_editor, the filter runs inside the get_image_send_to_editor function which is resposible for sending the link HTML that surrounds images sent to the editor. The filter can be found in core, in wp-admin/includes/media and is linked below for quick reference. core.trac.wordpress.org/browser/tags/3.1/wp-admin/includes/media.php

Get wp_get_attachment_url outside of loop

if the result you’re looking for is a printout of the URL, like in your example, then this should work: $page_id = get_queried_object_id(); if ( has_post_thumbnail( $page_id ) ) : $image_array = wp_get_attachment_image_src( get_post_thumbnail_id( $page_id ), ‘optional-size’ ); $image = $image_array[0]; else : $image = get_template_directory_uri() . ‘/images/default-background.jpg’; endif; echo $image;

Edit image / Delete image link

This isn’t 100% complete, but should be a good start for you. <a href=”https://wordpress.stackexchange.com/questions/31371/<?php echo wp_nonce_url(“/wp-admin/post.php?action=delete&amp;post=$post->ID”, ‘delete-attachment_’ . $post->ID ) ?>”><?php _e( ‘Delete Permanently’ ) ?></a> A couple notes on what you’ll have left to do: This will do no confirmation, so you’ll probably want to use JS to verify that it wasn’t clicked by … Read more

List most recent image uploads, but only for specific custom post type

Did you try adding a filter to get_posts. This isn’t tested, just a thought after a bit of searching : function my_filter( $query ) { if( is_home() ) //Example, if u want to display recent images on home { $query->set( ‘post_type’, array( ‘attachment’, ‘my_cpt’ ) ); } } add_filter( ‘pre_get_posts’, ‘my_filter’ ); EDIT : After … Read more

Remove duplicate attachments

function get_attachment_files(){ $args = array( ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ => 0 ); $attachments = get_posts($args); if ($attachments) { foreach ($attachments as $post) { setup_postdata($post); wp_delete_post( $post->ID ); } } } add_action(‘admin_init’,’get_attachment_files’); adapted from: http://wpsnipp.com/index.php/functions-php/list-all-unattached-files-in-media-library/ I’d be careful of this though, because I am not sure it won’t delete the … Read more

complex restriction of items in media library

Good code. I think you could simplify by making direct SQL queries instead: — Featured Images SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` = ‘_thumbnail_id’; –> $thumbnail_ids — Header Images SELECT `post_id` FROM `wp_postmeta` WHERE `meta_key` = ‘_wp_attachment_context’ and `meta_value` = ‘custom-header’; –> $header_ids Also, with your method, I think that if you call WP_Query with … Read more

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