Get attachments by user

Use a custom query for this. $user_id = 1; $the_query = new WP_Query( array( ‘post_type’ => ‘attachment’, ‘post_status’ => ‘inherit’, ‘author’ => $user_id) ); if ( $the_query->have_posts() ) while ( $the_query->have_posts() ) : $the_query->the_post(); the_title(); endwhile; This will show all the attachment titles for user with user id 1. You can use get_the_ID() in the … Read more

How can I autopopulate titles in the media library?

If you can do SQL manually then try: UPDATE wp_posts p INNER JOIN wp_posts q ON p.post_type=”attachment” AND p.post_mime_type LIKE ‘image/%’ AND (p.post_title IS NULL OR LENGTH(p.post_title) = 0) AND p.post_parent = q.ID SET p.post_title = q.post_title; If you need a PHP function then try: function set_image_without_title_to_post_title() { global $wpdb; $sql = sprintf( “UPDATE %s … Read more

resize from small images to large

Found a solution here that is working: http://www.binarynote.com/how-to-perfectly-upscale-image-in-wordpress.html function binary_thumbnail_upscale( $default, $orig_w, $orig_h, $new_w, $new_h, $crop ) { if ( !$crop ) return null; $aspect_ratio = $orig_w / $orig_h; $size_ratio = max($new_w / $orig_w, $new_h / $orig_h); $crop_w = round($new_w / $size_ratio); $crop_h = round($new_h / $size_ratio); $s_x = floor( ($orig_w – $crop_w) / 2 … Read more

Is it possible to modify the media library admin screen?

That area of all admin screens is where admin notices are displayed, so you could generate an admin notice. Here’s a suitable function and hook: function wpse_233031_admin_notice() { ?> <div class=”notice notice-info”> <p>Your message here!</p> </div> <?php } function wpse_233031_hook_admin_notice() { add_action( ‘admin_notices’, ‘wpse_233031_admin_notice’ ); } add_action( ‘load-upload.php’, ‘wpse_233031_hook_admin_notice’ ); /* Edited out anonymous function … Read more

Remove image from post also removes photo from media library

Don’t know if there is an easy way out but you can do this to achieve: Introduce an admin js in your functions.php like this: //Admin JS add_action(‘admin_init’, ‘custom_admin_js’); function custom_admin_js() { wp_register_script( ‘admin-js’, get_stylesheet_directory_uri() . ‘/js/admin.js’ ); wp_enqueue_script( ‘admin-js’ ); } The js file will go in the theme you are using make another … Read more

Image picker widget

Try this code. class Image_Picker extends WP_Widget { function Image_Picker() { $widget_ops = array(‘classname’ => ‘Image_Picker’, ‘description’ => ‘Pick 2 images from media library’); $this->WP_Widget(‘Image_Picker’, ‘Image Picker’, $widget_ops); } function form($instance) { //WIDGET BACK-END SETTINGS $instance = wp_parse_args((array) $instance, array(‘link1’ => ”, ‘link2’ => ”)); $link1 = $instance[‘link1’]; $link2 = $instance[‘link2’]; $images = new WP_Query( … Read more

Uploading images: ‘ø’ get replaced with ‘ø’

WP sanitize_file_name() function doesn’t handle those characters by default. You can add filter and sanitize those to avoid encoding issues. function mamaduka_sanitize_file_name( $filename ) { $filename = strtr($filename, ‘ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïñòóôõöøùúûüýÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƒƠơƯưǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǺǻǼǽǾǿ’, ‘SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyyAAAAAAAECEEEEIIIIDNOOOOOOUUUUYsaaaaaaaeceeeeiiiinoooooouuuuyyAaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIiIJijJjKkLlLlLlLlllNnNnNnnOoOoOoOEoeRrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzsfOoUuAaIiOoUuUuUuUuUuAaAEaeOo’); return $filename; } add_filter( ‘sanitize_file_name’, ‘mamaduka_sanitize_file_name’ ); Code example for this trac comment – https://core.trac.wordpress.org/ticket/16330#comment:22.

How do I programmatically add an image to a post?

Hey I used this code for something similar(I was also downloading remote image and uploading to WordPress site). Please have a look: $image_url = $value;//This is the sanitized image url. $image = pathinfo($image_url);//Extracting information into array. $image_name = $image[‘basename’]; $upload_dir = wp_upload_dir(); $image_data = file_get_contents($image_url); $unique_file_name = wp_unique_filename($upload_dir[‘path’], $image_name); $filename = basename($unique_file_name); $postarr = array( … Read more

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