• Resolved Anthony Martin

    (@spidlace)


    Hi,

    Thanks for your plugin !
    I want to change the PDF icon with his thumbnail (custom thumbnail).

    But I can’t because, there are no hooks in the function “_build_item_thumbnail” (class-mla-list-table.php)
    Is it possible to add a hook like this for change icon for all media ?

    $thumb = apply_filters('mla_list_table_change_icon', $item->ID); (l.818)

    Thanks a lot,
    Anthony

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

    (@dglingren)

    Good to hear from you again; thanks for the kind words and for your question.

    MLA uses a standard WordPress function, wp_get_attachment_image(), to generate its thumbnail markup. There is an existing filter in that function you can hook to get the results you seek:

            /**
             * Filters the list of attachment image attributes.
             *
             * @since 2.8.0
             *
             * @param array        $attr       Attributes for the image markup.
             * @param WP_Post      $attachment Image attachment post.
             * @param string|array $size       Requested size. Image size or array of width and height values
             *                                 (in that order). Default 'thumbnail'.
             */
            $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size );
    

    I am marking this topic resolved, but if you have any problems or further questions about using the above filter to accomplish your goal, post an update and I will investigate further. Thanks for your continued interest in the plugin.

    Thread Starter Anthony Martin

    (@spidlace)

    Hi David,

    Thanks for your response.

    There is indeed a hook in the standard function wp_get_attachment_image(), but all my pdf don’t go in this hook because in the function wp_get_attachment_image, they don’t have image src..

    But, I hook into function wp_get_attachment_image_src() and I get the good result !
    This is how I make, if someone is interested :

    if(!function_exists('sp_change_icon_pdf_media')){
        function sp_change_icon_pdf_media($image, $attachment_id, $size, $icon){
    
            global $pagenow;
    
            if(!is_admin() && $pagenow != 'upload.php')  return $image;
            
            $mime_type = get_post_mime_type($attachment_id);
            if($mime_type == 'application/pdf'){
                // Do stuff
                $url = 'https://www.domain.com/test.jpg';
            } else $url = '';
            
            return array($url, 64, 64, $icon);
        }
        add_filter('wp_get_attachment_image_src', 'sp_change_icon_pdf_media', 10, 4);
    }

    Thanks again David,
    Anthony

    Plugin Author David Lingren

    (@dglingren)

    Thanks for adapting my suggestion and finding a better solution! Thanks as well for sharing your code so other users can benefit from it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add Hook for icon media’ is closed to new replies.