I managed to isolate the gallery images from the Media Library using a wordpress core filter.
(using WordPress 3.5.1, plugin version 0.1.2)
See the code bellow. Can you help me to point out how can I isolate the folder images from the insert media popup box?
I’m new in that one, and I’m sure without help I can figure out in a few days, but though you could give me some hints.
// Isolate gallery images from Media Library
if ( is_admin() && is_plugin_active('eazyest-gallery/eazyest-gallery.php') ) {
/**kli map wp
* Count number of attachments for the mime type(s).
*
* If you set the optional mime_type parameter, then an array will still be
* returned, but will only have the item you are looking for. It does not give
* you the number of attachments that are children of a post. You can get that
* by counting the number of children that post has.
*
* @since 2.5.0
*
* @param string|array $mime_type Optional. Array or comma-separated list of MIME patterns.
* @return array Number of posts for each mime type.
*/
function kli_ezg_wp_count_attachments( $mime_type = '' ) {
global $wpdb;
$and = wp_post_mime_type_where( $mime_type );
/*kli
* Exclude some media items
* - append to $and
*/
$attachment_base_url = eazyest_gallery()->address();
$and .= " AND $wpdb->posts.guid NOT LIKE '{$attachment_base_url}%'";
$count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A );
$stats = array();
foreach( (array) $count as $row ) {
$stats[$row['post_mime_type']] = $row['num_posts'];
}
$stats['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and");
return (object) $stats;
}
/**kli map wp
* Display the list of views available on this table.
*
* @since 3.1.0
* @access public
*/
function kli_ezg_get_views() {
global $wpdb, $post_mime_types, $avail_post_mime_types;
$type_links = array();
$_num_posts = (array) kli_ezg_wp_count_attachments();
$_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
if ( !isset( $total_orphans ) )
$total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" );
$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
foreach ( $matches as $type => $reals )
foreach ( $reals as $real )
$num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
//*kli map
$this_detached = isset( $_REQUEST['detached'] ) || isset( $_REQUEST['find_detached'] );
// $class = ( empty($_GET['post_mime_type']) && !$this->detached && !isset($_GET['status']) ) ? ' class="current"' : '';
$class = ( empty($_GET['post_mime_type']) && !$this_detached && !isset($_GET['status']) ) ? ' class="current"' : '';
$type_links['all'] = "<a href='upload.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files' ), number_format_i18n( $_total_posts ) ) . '</a>';
foreach ( $post_mime_types as $mime_type => $label ) {
$class = '';
if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
continue;
if ( !empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
$class = ' class="current"';
if ( !empty( $num_posts[$mime_type] ) )
$type_links[$mime_type] = "<a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>';
}
$type_links['detached'] = '<a href="upload.php?detached=1"' . ( $this_detached ? ' class="current"' : '' ) . '>' . sprintf( _nx( 'Unattached <span class="count">(%s)</span>', 'Unattached <span class="count">(%s)</span>', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</a>';
if ( !empty($_num_posts['trash']) )
$type_links['trash'] = '<a href="upload.php?status=trash"' . ( (isset($_GET['status']) && $_GET['status'] == 'trash' ) ? ' class="current"' : '') . '>' . sprintf( _nx( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</a>';
return $type_links;
}
// Update wp_query for Media Library
// - in kli_ezg_medialibrary_exclude
function kli_ezg_medialibrary_exclude_wp_query( $content ) {
global $wpdb;
$attachment_base_url = eazyest_gallery()->address();
$content .= " AND $wpdb->posts.guid NOT LIKE '{$attachment_base_url}%'";
return $content;
}
// Exclude some media items from Media Library
function kli_ezg_medialibrary_exclude( $input ) {
add_filter( 'posts_where_paged', 'kli_ezg_medialibrary_exclude_wp_query' );
add_filter( 'views_upload', 'kli_ezg_get_views' );
return $input;
}
add_filter( 'upload_per_page', 'kli_ezg_medialibrary_exclude' );
}// if plugin active