• Resolved Byron

    (@blutz)


    I needed this plugin to work with the most recent version of WordPress (3.5 right now) so I made some modifications and fixed some of the bugs so that the plugin works. (Not sure if it works on the Add Media pages though.)

    Feel free to download it: https://github.com/blutz/media-credit

    It’s not easily upgradeable from Scott’s latest version here (I removed the closing shortcode tag and its placement) so if someone wants to write a converter and test this, we can probably integrate everything back here.

    https://www.ads-software.com/extend/plugins/media-credit/

Viewing 15 replies - 46 through 60 (of 71 total)
  • Plugin Contributor Scott Bressler

    (@sbressler)

    No, [caption] was definitely there in old versions (running a old version here to test). So I don’t understand — did the caption shortcode use to allow shortcodes within but it doesn’t any longer?

    Plugin Author pepe

    (@pputzer)

    Plugin Contributor Scott Bressler

    (@sbressler)

    But Media Credit doesn’t use either img_caption_shortcode or add_shortcode(‘caption’)…

    Plugin Author pepe

    (@pputzer)

    Yes, but the format of the caption shortcode changed. Before 3.4 it was [caption caption='foo']<img ...>[/caption] while now it is [caption]foo[/caption]. The shortcode still supports the old syntax if you change it manually. I would bet (haven’t tried it, though) that if you do that, [media-credit] parses correctly.

    I can confirm that on our site, in several hundred pre-3.4 instances of [caption caption='foo']<img ...>[/caption] the [media-credit] shortcode is parsed correctly, if that helps.

    Plugin Author pepe

    (@pputzer)

    I just checked in a new version that fixes the shortcode parsing. The problem was hidden in the mechanism used to make the >= 3.4 caption backwards compatible: The caption is captured via a regexp and added as an attribute. Of course, the stock WP shortcode does not know about [media-credit] and therefore only looks for <a> and <img>.

    If you want to try the fix without a repository checkout, add the following code to media-credit.php:

    add_shortcode('wp_caption', 'media_credit_caption_shortcode');
    add_shortcode('caption', 'media_credit_caption_shortcode');
    
    function media_credit_caption_shortcode($attr, $content = null) {
            // New-style shortcode with the caption inside the shortcode with the link and image tags.
            if ( ! isset( $attr['caption'] ) ) {
                    if ( preg_match( '#((?:\[media-credit[^\]]+\]\s*)(?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?(?:\s*\[/media-credit\])?)(.*)#is', $content, $matches ) ) {
                            $content = $matches[1];
                            $attr['caption'] = trim( $matches[2] );
                    }
            }
    
            return img_caption_shortcode($attr, $content);
    }
    Plugin Contributor Scott Bressler

    (@sbressler)

    Awesome, thanks for addressing!
    Didn’t Nacin say not to use add_shortcode(‘wp_caption’), though?

    Plugin Author pepe

    (@pputzer)

    He did, but I think that only applies for plugins that want to change the shortcode output. Here, I don’t see any other way to do it. At the point of the filter, the $content is already mangled beyond repair.

    I’m not familiar with how Media Credit stores its information. When img_caption_shortcode() parses out the image and caption from $content, what happens to the media credit? How is it “mangled”?

    Plugin Author pepe

    (@pputzer)

    Slightly simplified (no attributes) code for media-credit with captions:
    [caption][media-credit]<a><img></a>[/media-credit] My Caption[/caption]

    The regexp in media.php starts matching at the <a> tag and ignores everything before it. This eliminates the [media-credit] tag and its attributes and leaves a dangling [/media-credit] that can’t be parsed by the shortcode function.

    Plugin Contributor Scott Bressler

    (@sbressler)

    Nacin, any ideas?

    Plugin Author pepe

    (@pputzer)

    Has anyone tried the current trunk version (with the caption shortcode fix)?

    Plugin Author pepe

    (@pputzer)

    No-one? If there are no objections, I’d like to release the current version to get some feedback. Since the current version is broken on 3.5/3.6 in multiple ways, I see no harm that could befall users.

    Sorry Pepe,

    I fully intend on revisiting this project, but I have a ton of projects on my plate right now. I’ll see if I can’t do some beta testing for my particular situation this weekend.

    Hi Pepe,

    Slight bug I’ve found. When inserting the media in visual editor, the initial [media-credit] tag is not inserted. (however, the [/media-credit] is). In the text editor, this is not a problem. Additionally, if you switch from text editor, to visual, and back the first [media-credit] seems to disappear.

Viewing 15 replies - 46 through 60 (of 71 total)
  • The topic ‘WP 3.5 Compatible version (download here)’ is closed to new replies.