• Resolved klihelp

    (@klihelp)


    There is no way to share gallery images between folders.

    Is there any way to don’t show gallery images in Media Library?
    And the other thing is to prevent inserting gallery images into other post types?
    Or at least to make it filterable, so users can see in the Media Popup box if they really want to insert an image from the Folders or they could upload their version.
    The reason for this is that FTP galleries will remove/update their images often and by bulk.
    This optional method could save a lot of memory and cpu for some servers.

    https://www.ads-software.com/extend/plugins/eazyest-gallery/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Marcel Brinkkemper

    (@macbrink)

    I have nothing planned like this.

    Thread Starter klihelp

    (@klihelp)

    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
    Thread Starter klihelp

    (@klihelp)

    Here is the code to not show Eazyest Gallery items in Media Popup for other post types.

    ps: looks like the plugin already doing something similar, because only sharing the gallery images with the POST custom post type.

    /** Exclude Eazyest Gallery from Media Popup when not in folders
         *
         */
        function kli_ezg_mediapopup_exclude() {
            if ( ! eazyest_folderbase()->refered_by_folder() )
                add_filter( 'posts_where_paged', 'kli_ezg_medialibrary_exclude_wp_query', 1 );
        }
        add_action( 'wp_ajax_query-attachments', 'kli_ezg_mediapopup_exclude', 1 );

    From here, it would be easy to create an isolation option.

    Thread Starter klihelp

    (@klihelp)

    There is one more thing to do –

    Un-Attached counter shows the number of eazyest gallery zomby attachments.

    Thread Starter klihelp

    (@klihelp)

    WordPress 3.7 have new filters to use:
    ajax_query_attachments_args – https://core.trac.www.ads-software.com/ticket/24285
    count_posts – https://core.trac.www.ads-software.com/changeset/25554

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Isolate gallery images from other post types and Media library?’ is closed to new replies.