• Resolved Rick Tuttle

    (@papasoft)


    Thanks for this wonderful plugin. I have set up Att. Categories and am able to filter the media in the loader popup when I am adding an image.

    I would like to programmatically set the Att. Category in some instances so that only those attachments that are from that category are displayed when the media loader is initially opened.

    What is the best way to do that? I see there is a parameter for mla_filter_term that can be passed in and I’m assuming that is what I would use. What I can’t find is the right filter to call to set this term in some cases and not in others.

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for the good words and for your interesting question. To put it in a more general way, I understand that you want to set the initial values of the Media Manager Modal Window (MMMW) toolbar controls (MIME type, Year/Month, Taxonomy term and search box) and have the initial set of media items displayed in the Modal Window reflect the choice(s). Is that right?

    There is no function in the current MLA version for this purpose, but I might be able to add one or more filters/hooks that you could use. This may take some experimentation, since the toolbar controls are generated by MMMW code and it is not immediately evident how to set their initial values or how to make the initial query for media library items reflect their settings.

    Assuming I can do something in this area, would providing filters/hooks be a solution you can work with? When you say “”set the Att. Category in some cases” and “set this term in some cases and not in others“, what information do you need to make your decision?

    I can’t promise a solution, but if you can give me more information I can be more helpful. Thanks for the question and for your interest in the plugin.

    Thread Starter Rick Tuttle

    (@papasoft)

    Using a filter/hook is exactly what I would want to use. Functionally, images would get uploaded and assigned to a category and then someone else would come along on a particular post type, let’s say and when the modal window appears it would already filter the images based on that Att. Category.

    I hope that helps. If you have any guidance I may also be able to assist in coding.

    Plugin Author David Lingren

    (@dglingren)

    Thanks you for confirming that a new filter/hook would be appropriate for your application. I have developed a new mla_media_modal_initial_filters hook and an example plugin that illustrates its use. You will have to add logic for picking the initial Att. Category term ID based on post type or any other criteria to this new filter:

    /**
     * MLA Edit Media Initial Filters Filter
     *
     * This filter gives you an opportunity to change the initial values of the
     * Media Manager Modal Window toolbar controls.
     *
     * @since 1.00
     *
     * @param    array    toolbar control initial values
     *
     * @return    array    updated toolbar control initial values
     */
    public static function mla_media_modal_initial_filters_filter( $initial_values ) {
        /*
         * Uncomment the error_log statements in any of the filters to see what's passed in
         */
        //error_log( 'MLAMediaModalExample::mla_media_modal_initial_filters_filter $initial_values = ' . var_export( $initial_values, true ), 0 );
    
        /*
         * The default initial values are:
         *
         * $initial_values = array(
         *     'filterMime' => 'all',
         *     'filterMonth' => 0,
         *     'filterTerm' => 0,
         *     'searchConnector' => 'AND',
         *     'searchFields' => array( 'title', 'content' ),
         *     'searchValue' => '',
         * );
         *
         * Other values include:
         *     filterMime: uploaded, image, audio, video, text, application, detached
         *     filterMonth: year and month, e.g., '201407'
         *     filterTerm: term ID in the selected taxonomy (NOT term-taxonomy ID)
         *     searchConnector: 'OR'
         *     searchFields: name (slug), alt-text, excerpt (caption), terms
         */
    
        // uncomment next lines to set initial values
        //$initial_values['filterMime'] = 'image';
        //$initial_values['filterMonth'] = '201404';
        //$initial_values['filterTerm'] = 175; // term ID in attachment_tags
        //$initial_values['searchConnector'] = 'OR';
        //$initial_values['searchValue'] = 'de la';
    
        return $initial_values;
    } // mla_media_modal_initial_filters_filter

    The new hook will be in my next MLA version. If you’d like to test the hook, please send me a note with your e-mail address and I will give you a copy by return e-mail. You can use the Contact Us page at our web site:

    Fair Trade Judaica/Contact Us

    Thanks for your help and your patience.

    Plugin Author David Lingren

    (@dglingren)

    I have released MLA v1.91, which contains the new hook.

    I am marking this topic resolved, but please update it if you have any trouble with the new version.

    Thanks again for your help and for your interest in the plugin.

    Lacy

    (@katielacy-1)

    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;
    Plugin Author David Lingren

    (@dglingren)

    @lacy,

    I have started a new topic for your question and responded to both of your posts there. Please continue the dialog in this new topic:

    Filtering Media Manager Toolbar Controls and Items Displayed

    Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Filter media in popup on load’ is closed to new replies.