Change the default-view of Media Library in 3.5?

There were two minor mistakes in my previous answer: I forgot to trigger the change event for the parent. I called the function on every AJAX call, making other selections impossible. Here is the fixed code: <?php /** * Plugin Name: Pre-select post specific attachments */ add_action( ‘admin_footer-post-new.php’, ‘wpse_76048_script’ ); add_action( ‘admin_footer-post.php’, ‘wpse_76048_script’ ); function … Read more

Media Library not showing images when adding to Posts (but retrieving image info via ajax)

In case any poor soul runs in to something similar, I’ve found the problem: define(‘WP_DEBUG’, false); Running debug mode (as I do on all dev sites), was throwing a warning, but it was being returned in the ‘admin-ajax.php’ which was preventing the images from showing/uploading and returning the appropriate values etc. I cannot believe the … Read more

Create gallery doesn’t show uploaded images

I finally found that it is caused from the PHP5.5 version, and it’s because of the deprecated function mysql_connect(). I’ve benn able to solve it by changing the file /wp-includes/wp-db.php (line 1142). $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); Change with: $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); This makes the … Read more

Get filenames of available image sizes

/** *** return_image_thumbnails *** – return a list of thumbnails based on filesystem report. *** @param (string) $image – Original image location. *** @return (array) $results *** @author Oleg Butuzov **/ if (!function_exists(‘return_image_thumbnails’)){ function return_image_thumbnails($image){ $extension = array_pop(explode(‘.’, basename($image))); if (!file_exists($image) || !(@getimagesize($image))) return array(); return glob(dirname($image).”https://wordpress.stackexchange.com/”.basename($image, ‘.’.$extension).’-[0-9]*x[0-9]*.’.$extension); } } usage example return_image_thumbnails(get_attached_file( $image_id ));

When I’m in post editor and click on ‘Add media’, why won’t it load the media library with this code?

The correct hook to add/remove menus in admin area is admin_menu. Also, be aware that current_user_can is intented to check user capabilities, not user roles. See current_user_can documentation and notes. add_action( ‘admin_menu’, ‘my_remove_menu_pages’ ); function my_remove_menu_pages() { $user = wp_get_current_user(); if( ! empty( $user ) && in_array( “contributor”, (array) $user->roles ) ) { remove_menu_page(‘tools.php’); // … Read more