Plugin Directory

Changeset 1045461


Ignore:
Timestamp:
12/16/2014 05:34:55 AM (11 years ago)
Author:
sewpafly
Message:

6.0 adds filters

Location:
post-thumbnail-extras
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • post-thumbnail-extras/tags/6.0/README.txt

    r982766 r1045461  
    44Tags: post-thumbnail, post thumbnail, featured image, awesome, media library, shortcode, shortcodes
    55Requires at least: 2.5
    6 Tested up to: 4.0
     6Tested up to: 4.0.x
    77Stable tag: trunk
    88License: GPLv2
     
    5555== Changelog ==
    5656
     57= 6.0 =
     58
     59* Added `ptx_html_attrs` filter for modifying the html output
     60* Fixed the `shortcode_atts` so that the `shortcode_atts_ptx` filter will fire
     61
    5762= 5.0 =
    5863
     
    8085== Upgrade Notice ==
    8186
    82 = 5.0 =
     87= 6.0 =
    8388
    84 Upgrade for wordpress 3.8 and bug fixes
     89Added some filters
  • post-thumbnail-extras/tags/6.0/php/shortcode.php

    r982765 r1045461  
    99        add_filter( 'image_size_names_choose', array( $this, 'image_sizes' ) );
    1010        add_filter( 'wp_prepare_attachment_for_js', array( $this, 'fix_attachment' ), 10, 3 );
     11        add_filter( 'ptx_html_attrs', array( $this, 'html_attrs' ), 10, 2 );
    1112    }
    1213
     
    2324    public function parse_shortcode( $attrs ) {
    2425        $post = get_post();
    25         extract( shortcode_atts( array(
     26        $a = shortcode_atts( array(
    2627            'id' => get_post_thumbnail_id( $post->ID ),
    2728            'size' => 'thumbnail',
    2829            'class' => 'pt-post-thumbnail',
    29             'link' => 'none'
    30         ), $attrs ) );
     30            'link' => 'none',
     31            'html_attrs' => 'class', // should be a list of attrs to look for (comma-separated)
     32        ), $attrs, 'ptx' );
    3133
    32         if ( ! wp_attachment_is_image( $id ) ) return;
     34        if ( ! wp_attachment_is_image( $a['id'] ) ) return;
    3335
    34         $html = wp_get_attachment_image( $id, $size, false, array( 'class' => $class ) );
     36        $html_attrs = apply_filters('ptx_html_attrs', array(), $a);
    3537
    36         switch( $link ) {
     38        $html = wp_get_attachment_image( $a['id'], $a['size'], false, $html_attrs );
     39
     40        switch( $a['link'] ) {
    3741        case 'none':
    3842            return $html;
    3943            break;
    4044        case 'file':
    41             $link_url = wp_get_attachment_url( $id );
     45            $link_url = wp_get_attachment_url( $a['id'] );
    4246            break;
    4347        case 'post':
    44             $link_url = get_attachment_link( $id );
     48            $link_url = get_attachment_link( $a['id'] );
    4549            break;
    4650        default:
    47             $link_url = $link;
     51            $link_url = $a['link'];
    4852        }
    4953
    5054        return "<a href='$link_url'>$html</a>";
     55    }
     56
     57    /**
     58     * Add attributes to the html src
     59     * @param $attrs that have been defined already
     60     * @param $attrs defined from the shortcode
     61     */
     62    public function html_attrs( $attrs, $shortcode_attrs ) {
     63        foreach ( explode(',', $shortcode_attrs['html_attrs']) as $attr) {
     64            if ( in_array( $attr, $shortcode_attrs ) ) {
     65                $attrs[$attr] = $shortcode_attrs[$attr];
     66            }
     67        }
     68        return $attrs;
    5169    }
    5270
  • post-thumbnail-extras/tags/6.0/post-thumbnail-extras.php

    r982765 r1045461  
    55Author: sewpafly
    66Author URI: http://sewpafly.github.io/post-thumbnail-editor/
    7 Version: 5.1
     7Version: 6.0
    88Description: Little things that make using post thumbnails easier
    99*/
  • post-thumbnail-extras/trunk/README.txt

    r982766 r1045461  
    44Tags: post-thumbnail, post thumbnail, featured image, awesome, media library, shortcode, shortcodes
    55Requires at least: 2.5
    6 Tested up to: 4.0
     6Tested up to: 4.0.x
    77Stable tag: trunk
    88License: GPLv2
     
    5555== Changelog ==
    5656
     57= 6.0 =
     58
     59* Added `ptx_html_attrs` filter for modifying the html output
     60* Fixed the `shortcode_atts` so that the `shortcode_atts_ptx` filter will fire
     61
    5762= 5.0 =
    5863
     
    8085== Upgrade Notice ==
    8186
    82 = 5.0 =
     87= 6.0 =
    8388
    84 Upgrade for wordpress 3.8 and bug fixes
     89Added some filters
  • post-thumbnail-extras/trunk/php/shortcode.php

    r982765 r1045461  
    99        add_filter( 'image_size_names_choose', array( $this, 'image_sizes' ) );
    1010        add_filter( 'wp_prepare_attachment_for_js', array( $this, 'fix_attachment' ), 10, 3 );
     11        add_filter( 'ptx_html_attrs', array( $this, 'html_attrs' ), 10, 2 );
    1112    }
    1213
     
    2324    public function parse_shortcode( $attrs ) {
    2425        $post = get_post();
    25         extract( shortcode_atts( array(
     26        $a = shortcode_atts( array(
    2627            'id' => get_post_thumbnail_id( $post->ID ),
    2728            'size' => 'thumbnail',
    2829            'class' => 'pt-post-thumbnail',
    29             'link' => 'none'
    30         ), $attrs ) );
     30            'link' => 'none',
     31            'html_attrs' => 'class', // should be a list of attrs to look for (comma-separated)
     32        ), $attrs, 'ptx' );
    3133
    32         if ( ! wp_attachment_is_image( $id ) ) return;
     34        if ( ! wp_attachment_is_image( $a['id'] ) ) return;
    3335
    34         $html = wp_get_attachment_image( $id, $size, false, array( 'class' => $class ) );
     36        $html_attrs = apply_filters('ptx_html_attrs', array(), $a);
    3537
    36         switch( $link ) {
     38        $html = wp_get_attachment_image( $a['id'], $a['size'], false, $html_attrs );
     39
     40        switch( $a['link'] ) {
    3741        case 'none':
    3842            return $html;
    3943            break;
    4044        case 'file':
    41             $link_url = wp_get_attachment_url( $id );
     45            $link_url = wp_get_attachment_url( $a['id'] );
    4246            break;
    4347        case 'post':
    44             $link_url = get_attachment_link( $id );
     48            $link_url = get_attachment_link( $a['id'] );
    4549            break;
    4650        default:
    47             $link_url = $link;
     51            $link_url = $a['link'];
    4852        }
    4953
    5054        return "<a href='$link_url'>$html</a>";
     55    }
     56
     57    /**
     58     * Add attributes to the html src
     59     * @param $attrs that have been defined already
     60     * @param $attrs defined from the shortcode
     61     */
     62    public function html_attrs( $attrs, $shortcode_attrs ) {
     63        foreach ( explode(',', $shortcode_attrs['html_attrs']) as $attr) {
     64            if ( in_array( $attr, $shortcode_attrs ) ) {
     65                $attrs[$attr] = $shortcode_attrs[$attr];
     66            }
     67        }
     68        return $attrs;
    5169    }
    5270
  • post-thumbnail-extras/trunk/post-thumbnail-extras.php

    r982765 r1045461  
    55Author: sewpafly
    66Author URI: http://sewpafly.github.io/post-thumbnail-editor/
    7 Version: 5.1
     7Version: 6.0
    88Description: Little things that make using post thumbnails easier
    99*/
Note: See TracChangeset for help on using the changeset viewer.