Use Media Uploader in Plugin

Try using this code: define(“ME_URL”, rtrim(WP_PLUGIN_URL,”https://wordpress.stackexchange.com/”) . “https://wordpress.stackexchange.com/” . basename(dirname(__FILE__))); define(“ME_DIR”, rtrim(dirname(__FILE__), “https://wordpress.stackexchange.com/”)); function my_admin_scripts() { wp_enqueue_script(‘media-upload’); wp_enqueue_script(‘thickbox’); } function my_admin_styles() { wp_enqueue_style(‘thickbox’); } add_action(‘admin_print_scripts’, ‘my_admin_scripts’); add_action(‘admin_print_styles’, ‘my_admin_styles’); <td> <img src=”<?php echo esc_attr( get_the_author_meta( ‘profileimage’, $user->ID ) ); ?>” id=”ppimage”> <input type=”text” name=”profileimage” id=”profileimagetxt” value=”<?php echo esc_attr( get_the_author_meta( ‘profileimage’, $user->ID ) ); ?>” class=”regular-text” /><br … Read more

Add suffix to filename of uploaded images

I did it in a different way. I just had to update the code from Gerasimos Tsiamalos Retina Plugin to WordPress 3.5., using image editor instead of image resize. This is how it looks like: function nothing_image_make_retina_size($file, $width, $height, $crop=false) { if ( $width || $height ) { $resized_file = wp_get_image_editor($file); if ( ! is_wp_error( … Read more

How to get custom image sizes into media uploader dropdown?

Try seperating it like this: function setup_image_sizes() { if ( function_exists( ‘add_image_size’ ) ) { add_image_size( ‘post-image’, 608, 350, true ); } } add_action( ‘after_setup_theme’, ‘setup_image_sizes’ ); function post_image_sizes($sizes){ $custom_sizes = array( ‘post-image’ => ‘Post Image’ ); return array_merge( $sizes, $custom_sizes ); } add_filter(‘image_size_names_choose’, ‘post_image_sizes’); That way it is working in my setup. Additional Sources: … Read more

How to add a rel attribute to images that contains their categories?

This should work for the rel attribute: /** * Create a rel attribute from the image categories * * @see http://wordpress.stackexchange.com/a/158024/26350 */ add_filter( ‘get_image_tag’, function( $html, $id ) { $rel = array(); foreach( (array) get_the_category( $id ) as $cat ) { $rel[] = $cat->slug; } return str_ireplace( ‘<img ‘, sprintf( ‘<img rel=”%s” ‘, join( ‘ … Read more

Get total number of pixels, size in megapixels and aspect ratio based on image width and height?

Sure – php can definitely handle simple math like this. All you’d have to do is reference the numbers coming back from the wp_get_attachment_image_src call: <?php if ( has_post_thumbnail()) { $full_image_info = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘full’); $img_h = $full_image_info[1]; $img_w = $full_image_info[2]; $total_pixels = $img_w * $img_h ; $megapixels = round($total_pixels) /* see http://at2.php.net/manual/en/function.round.php — they … Read more

How can I get a different image size, if all I have is the link?

I decided to use this, which is based on @AndresYanez’s answer: function get_image_id_by_link($link) { global $wpdb; $link = preg_replace(‘/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i’, ”, $link); return $wpdb->get_var(“SELECT ID FROM {$wpdb->posts} WHERE BINARY guid=’$link'”); } This is much more succinct (since it doesn’t jump through the hoops of first removing the extension and then adding it back in), and is … Read more

alt, title tags not showing

It actually depends upon how the image is shown in the template. If it is shown using a function like the_post_thumbnail() which returns complete html string to show image with alt then there should be no problem but if image is shown by only fetching URL then it depends how it is displayed . For … Read more