• ResolvedPlugin Author David Lingren

    (@dglingren)


    This new question deserves its own topic, so I am starting one in response to these posts in other support topics:

    —————————————-
    Posted on: Tuesday, May 26, 2015 9:07 AM
    Subject: Lacy on “[Plugin: Media Library Assistant] How to exclude a category from media libary.”

    Hey Guys,

    I have a category of Image bank which shouldn’t be shown to a specific user group. Could you point us in the right direction as to where we can filter the default loaded images not to included this category.

    ** I have already removed this category from the dropdown filter for this user group. Just need to exclude from the featured image media popup.

    Many Thanks!
    Katie

    ——————————————
    Posted on: Wednesday, May 27, 2015 4:22 AM
    Subject: Lacy on “[Plugin: Media Library Assistant] Filter media in popup on load”

    Hey guys,

    Please can you help me I would like to include a search for not in term. So I have one term id of 77 within “attachment_category” and if a user is in a group with no access to this category I wish to remove the images from the media modal popup.

    Please see my code ….

    $terms = get_terms( 'attachment_category' );
           if (current_user_can('administrator') || current_user_can('sales_marketing')) :
               $hasAccess = true;
           else :
               $hasAccess = false;
           endif;
        if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
            $termID = array();
            $imageBank = get_term_by('name', 'Image Bank', 'attachment_category');
            $imageBankId = $imageBank->term_id;
            foreach ( $terms as $term ) {
              $termID[$term->term_id] = $term->term_id;
             }
            if (!$hasAccess) :
            unset($termID[$imageBankId]);
            endif;
           $termID = implode(',' , $termID);
        }
        $initial_values['filterTerm'] = $termID; // This would be a not in if poss.
        return $initial_values;

    ——————————————

    First, I want to be sure I understand the question and the application goal. You wrote “exclude from the featured image media popup” and “remove the images from the media modal popup“. I understand that to mean you want to exclude all Media Library items (images) from the set that appears in the “thumbnails” area of the Media Manager Modal (popup) Window (MMMW); is that right?

    You wrote “I have already removed this category from the dropdown filter“. Is that the dropdown control in the toolbar on the MMMW, or another control? Is the code sample you posted related to this comment, or is it part of a proposed solution?

    Is it accurate to re-state your goal as “In the MMMW, I want to remove a term from the from the list in the dropdown control on the toolbar and I want to exclude all items assigned to that term from the set presented in the thumbnails area on the window”?

    Do you need to exclude the term from the list in the taxonomy meta box in the “ATTACHMENT DETAILS” pane of the MMMW?

    Do you need to exclude the term or the items from the Media/Assistant submenu table?

    If my restatement of the goal is correct, I believe the solution will require some new MLA hooks to allow the term list and the set of items returned to the MMMW. The existing mla_media_modal_initial_filters filter allows you to set the initial “selected value” for the controls but it does not allow the lists in the dropdown controls to be modified.

    If you can confirm my understanding and answer the above questions I will investigate the work required to enhance MLA to support your requirements. Thanks for any additional information you can provide.

    https://www.ads-software.com/plugins/media-library-assistant/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Lacy

    (@katielacy-1)

    Hi David,

    Thank you for the above. Here are the questions answered :

    I do wish to remove the images from the media pop up which are within a specific term.

    We have removed the term we wish to exclude from the search term dropdown.

    All the terms we wish to excluded are in the pop up as the other users do not have access to the MLA area. They can only view this when adding new or modifying a post.

    It would be great to extend the “mla_media_modal_initial_filters” hook to allow an exclude option or a NOT IN in the term relation.

    I hope this answers all of the above, and would like to thank you for your quick response and awesome plugin!

    Plugin Author David Lingren

    (@dglingren)

    Thank you for your response and for the kind words regarding the plugin and its support.

    I understand that you have answered “yes” to my question:

    Is it accurate to re-state your goal as “In the MMMW, I want to remove a term from the from the list in the dropdown control on the toolbar and I want to exclude all items assigned to that term from the set presented in the thumbnails area on the window”?

    You also wrote “We have removed the term we wish to exclude from the search term dropdown“, so the remaining task is:

    … I want to exclude all items assigned to that term from the set presented in the thumbnails area on the window

    I will investigate adding a new hook/filter to make that possible and I will post an update here when I have progress to report. Thanks for your patience and for your interest in the plugin.

    Plugin Author David Lingren

    (@dglingren)

    I have uploaded a new Development Version dated 20150609 that contains many new filters for the Media Manager Enhancements. I have also updated the /examples/mla-media-modal-hooks-example.php.txt example plugin to show how the new filters can be used to exclude items assigned to a particular term from the Query Attachments results.

    For the example I used the attachment_category taxonomy and one of the terms on my test system, admin. You can substitute any taxonomy and term you like for your own application. Here is the example code:

    /**
     * MLA Edit Media "Query Attachments" final terms Filter
     *
     * Gives you an opportunity to change the terms of the
     * Media Manager Modal Window "Query Attachments" query
     * after they are processed by the "Prepare List Table Query" handler.
     *
     * @since 1.01
     *
     * @param    array    WP_Query request prepared by "Prepare List Table Query"
     */
    public static function mla_media_modal_query_final_terms( $request ) {
        //error_log( 'MLAMediaModalExample::mla_media_modal_query_final_terms $request = ' . var_export( $request, true ), 0 );
    
        /*
         * Comment the next line out to remove items assigned to the
         *  Att. Categories "Admin" term from the query results.
         */
        return $request;
    
        if ( isset( $request['tax_query'] ) ) {
            $tax_query = $request['tax_query'];
            $tax_query['relation'] = 'AND';
        } else {
            $tax_query = array();
        }
    
        $tax_query[] = array( 'taxonomy' => 'attachment_category', 'operator' => 'NOT IN', 'field' => 'slug', 'terms' => 'admin' );
        $request['tax_query'] = $tax_query;
    
        //error_log( 'MLAMediaModalExample::mla_media_modal_query_final_terms altered $request = ' . var_export( $request, true ), 0 );
        return $request;
    } // mla_media_modal_query_final_terms

    The complete example plugin is included with the Development Version. You can find step-by-step instructions for using the Development Version in this earlier topic:

    MLA errors when using plugin

    If you get a chance to try the Development Version, let me know if there are any problems or further work required. I will leave this topic unresolved until the new filters and example are released in the next MLA version. Thanks for your question that inspired the new features.

    Plugin Author David Lingren

    (@dglingren)

    I have released MLA version 2.11. This version contains the new filters and example plugin for the taxonomy term filtering your application requires.

    I am marking this topic resolved, but please update it if you have any problems or further questions regarding the new filters or the example plugin. Thanks for your interest in MLA.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Filtering Media Manager Toolbar Controls and Items Displayed’ is closed to new replies.