detached = ( isset( $_REQUEST['attachment-filter'] ) && 'detached' === $_REQUEST['attachment-filter'] ); $this->modes = array( 'list' => __( 'List View' ), 'grid' => __( 'Grid View' ) ); parent::__construct( array( 'plural' => 'media', 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } /** * * @return bool */ public function ajax_user_can() { return current_user_can('upload_files'); } /** * * @global WP_Query $wp_query * @global array $post_mime_types * @global array $avail_post_mime_types * @global string $mode */ public function prepare_items() { global $wp_query, $post_mime_types, $avail_post_mime_types, $mode; list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST ); $this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' == $_REQUEST['attachment-filter']; $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; $this->set_pagination_args( array( 'total_items' => $wp_query->found_posts, 'total_pages' => $wp_query->max_num_pages, 'per_page' => $wp_query->query_vars['posts_per_page'], ) ); } /** * * @global wpdb $wpdb * @global array $post_mime_types * @global array $avail_post_mime_types * @return array */ protected function get_views() { global $wpdb, $post_mime_types, $avail_post_mime_types; $type_links = array(); $_num_posts = (array) wp_count_attachments(); $_total_posts = array_sum($_num_posts) - $_num_posts['trash']; $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)); $num_posts = array(); 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]; } } $selected = empty( $_GET['attachment-filter'] ) ? ' selected="selected"' : ''; $type_links['all'] = "'; foreach ( $post_mime_types as $mime_type => $label ) { if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) continue; $selected = ''; if ( !empty( $_GET['attachment-filter'] ) && strpos( $_GET['attachment-filter'], 'post_mime_type:' ) === 0 && wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $_GET['attachment-filter'] ) ) ) $selected = ' selected="selected"'; if ( !empty( $num_posts[$mime_type] ) ) $type_links[$mime_type] = ''; } $type_links['detached'] = ''; if ( !empty($_num_posts['trash']) ) $type_links['trash'] = ''; return $type_links; } /** * * @return array */ protected function get_bulk_actions() { $actions = array(); if ( MEDIA_TRASH ) { if ( $this->is_trash ) { $actions['untrash'] = __( 'Restore' ); $actions['delete'] = __( 'Delete Permanently' ); } else { $actions['trash'] = __( 'Trash' ); } } else { $actions['delete'] = __( 'Delete Permanently' ); } if ( $this->detached ) $actions['attach'] = __( 'Attach to a post' ); return $actions; } /** * @param string $which */ protected function extra_tablenav( $which ) { if ( 'bar' !== $which ) { return; } ?>