WordPress.org

Ready to get started?Download WordPress

Forums

swfObject Reloaded
[resolved] Can this plugin be used in templates? (7 posts)

  1. Jack
    Member
    Posted 2 years ago #

    I uploaded a swf and linked to it as being an attachment of that post. How can I use this plugin in attachment.php?

    I would like to link to swf's that open in attachment.php, and if possible with their native width and height, as set in Flash.

    http://wordpress.org/extend/plugins/swfobject-reloaded/

  2. CodeAndReload
    Member
    Plugin Author

    Posted 2 years ago #

    There isn't any need to. The Flash object is automatically inserted onto the attachment pages with the parameters specified on the attachment.

  3. Jack
    Member
    Posted 2 years ago #

    Then I'm still missing something I'm afraid.

    When I add the swf (choosing post url), I get this code inside my post:
    [swfobject]8599[/swfobject]

    This will open the swf inside the post, but I would like to open this swf inside the attachment page. I made two attachment pages to be sure: attachment.php and application.php. Inside I use the_content(), because I thought that was the only thing necessary.

  4. CodeAndReload
    Member
    Plugin Author

    Posted 2 years ago #

    That should be the only thing necessary, provided the the_content filter (mc_content) function runs, the post has a mime-type of 'application/x-shockwave-flash', it is not a feed (is_feed() is false)

    Some things to check:

    • the_content filters are being applied
    • Nothing is changing the_content as it is filtered after mc_content is run, maybe a plugin is changing the content after mc_content is run
    • the media's mime-type is "application/x-shockwave-flash"
    • is_feed is false
    • the $post global is initialized and is correct, perhaps a plugin is changing the $post global?

    A filter is applied early to the_content:

    add_filter( "the_content", "mc_content", -9999999999999999999);

    And when the filter is called on an attachment-page (attachment.php) the post object's mime-type should be "application/x-shockwave-flash" then the filter should add that stuff

    function mc_content ($content) {
    		global $post;
    		if (true && is_feed() && trim($post->post_content)) {
    			global $post, $shortcode_tags;
    			$tempElem = $shortcode_tags["swfobject"];
    			unset($shortcode_tags["swfobject"]);
    			$contentA = strip_shortcodes( $post->post_content );
    			$shortcode_tags["swfobject"] = $tempElem;
    			$content = do_shortcode($contentA);
    			return $content;
    		} elseif(is_feed()) {
    			return $content;
    		} <strong>elseif (get_post_mime_type( $post->ID )=="application/x-shockwave-flash"){
    			return "" . mc_swf_shortcode( null, $post->ID) . "<p>" .$post->post_excerpt ."</p><p>"  .$post->post_content ."</p>";
    		}</strong>
    		else return $content;
    	}

    Here is a live example, so I know it does work on an attachment page.
    http://codeandreload.com/post/gear-generator/gear-generator/

    WordPress does have functions to check the post's mime type, and a way to treat a string as if it had been run through all the shortcodes.

    if (get_post_mime_type( $the_posts_ID )=="application/x-shockwave-flash"){
       echo do_shortcode("[swfobject]$the_posts_ID[/swfobject]");
    }

    The above code should work as a kluge, but It would be nice to know why it isn't working. You'll need to change '$the_posts_ID' with the post's id.

    [Please post code snippets between backticks or use the code button.]

  5. Jack
    Member
    Posted 2 years ago #

    Damn, i'm still missing something I quess. Let me describe everything as good as I can...

    The post's mime type is correct. When I insert

    if (get_post_mime_type( $the_posts_ID )=="application/x-shockwave-flash"){
       echo do_shortcode("[swfobject]$the_posts_ID[/swfobject]");
    }

    it shows me the flash file twice on that page. Once inside the post, once because of this code.

    Second: Perhaps everything is working ok, but shouldn't I first GET to the attachment page? Doesn't the code

    [swfobject]number[/swfobject]

    only insert the swf at that point in the post? Shouldn't it first be a link the the attachment ID so it will open in attachment.php?

    Also, I don't understand what mc_content is. Is this part of your plugin? Do I have to insert that somewhere in my template?

  6. Jack
    Member
    Posted 2 years ago #

    I tried everything I can. I added is_feed and global $post checks to the attachment.php page, but I still feel that I can't 'reach' the attachment.php page because the current code only inserts the flash. There is no actual link to the file.

  7. Jack
    Member
    Posted 2 years ago #

    @CodeandReload: I think this can't be done with your plugin at this moment, but I managed to add the links manually inside application.php.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic