• I am running into a problem which baffles me as much as it irritates me. I’m coding a very simple pluging which will automatically insert the proper HTML for an image aligned left, right or in the centre of the page; and with or without caption. The format goes like so

    [image link="..." width="..." loc="..." caption="..."]

    After a spot of trouble with quotes within quotes and shutting off the WYSIWYG-editor, I managed to get the code working. Except, except for one mysterious bug.

    If I activate my plugin, and let WordPress apply it to a post, then the post will not display the body of the text if it contains more than a certain, variable number of words after I’ve first used the shortcode. I see the header, I see the comments, but the body of the post is completely blank. The addition of a single letter in a paragraph, as if it were a word, is sufficient to trigger the displaying or not of the blog contribution. If I deactivate the plugin, or render the shortcode dysfunctional by adding a letter to it (so it is no longer recognised as my shortcode), then the text reappears and can be as long as I want it to be.

    If I look at the source with my browser (either FF 3.6.x, FF 3.5.x or some ancient IE 6.x—yes, I know, I only keep it around for this sort of weirdness—) then the body is simply not there. WordPress is not sending it out.

    I have truly no idea what is happening here. I cannot even imagine why I’m seeing the behaviour as I do. I am not under the impression that the code I wrote is faulty, but obviously something is amiss. I’m posting the code here in a vain hope that someone will be able to pinpoint a problem; if there is no obvious problem then someone might want to log on to my test blog. It’s currently password protected and all that as I don’t want the URL to get out yet, so drop me a line in case you need access.

    <?php
    class BCode {
    
    	function BCode()
    	{
    
    		if (!function_exists('add_shortcode'))
    		    return;
    
    		add_shortcode('foto',array(&$this,'shortcode_foto'));
    	}
    
        /* Foto shortcode
         * Foto has attributes link (= filename), width (in px), loc (left, right, center),
         * and caption (some text). Caption is optional. There are no
         * default values.
         *
         */
    
        function shortcode_foto($atts=array(),$content=NULL)
        {
             extract($atts);
             if (isset($link) && isset($loc) && isset($width)) {
                  if ($loc=='left' || $loc=='right' || $loc=='center') {
                      $width=(int)$width;  // superfluous, I know
                      $link='https://bloggfx.localhost/'.$link;
                      $loc='align'.$loc;
    
                      if (isset($caption))
                          $i='<div class="wp-caption '.$loc.'" style="width: '.(10+$width).'px"><img class="size-full" src="'.$link.'" width="'.$width.'"/><p class="wp-caption-text">'.$caption.'</p></div>';
                      else
                          $i='<img class="'.$loc.' size-full" src="'.$link.'" width="'.$width.'" />';
                  }
             }
    
             // Here I either return a formatted-string or some easily
             // discernable error text.
             if (isset($i))
                return $i;
             else
                return '<span style="color: red;"><strong>[FOTOERROR]</strong></span>';
        }
    
    }
    
    // Start this plugin once all other plugins are fully loaded
    add_action( 'plugins_loaded', create_function( '', 'global $BCode; $BCode = new BCode();' ) );
    ?>
Viewing 1 replies (of 1 total)
  • Thread Starter cymric

    (@cymric)

    The cause was determined by some WordPress wizard to be related to an obscure runtime configuration setting in the PHP interpreter, specifically the one called ‘pcre.backtrack_limit’. Increasing this 10-fold from the deafult value of 1e5 by a line like

    ini_set('pcre.backtrack_limit', 1000000);

    in the initialisation code of the plugin made the bug disappear.

Viewing 1 replies (of 1 total)
  • The topic ‘Blog posts disappear upon addition of 1 word i.c.w. shortcode-plugin’ is closed to new replies.