Exemplo n.º 1
0
 /**
  * Assemble the caption as plain text.
  *
  * @param array $captiondata The caption data for the post retrieved from the database.
  * @param array $atts        The shortcode attributes, from which we determine which caption elements to include.
  *
  * @return string $caption        The caption plain text.
  */
 public function plaintext($captiondata, $atts = array())
 {
     // Start with an empty string
     $caption = '';
     // Get an instance of the shortcode class
     $shortcode = new Shortcode();
     // Since the source URL can't be combined with any other caption data in plain text, we'll start with that.
     if ($shortcode->has_flag('source-url', $atts, false) && !empty($captiondata['source_url'])) {
         return $captiondata['source_url'];
     }
     // Caption text
     if ($shortcode->has_flag('caption-text', $atts) && !empty($captiondata['caption_text'])) {
         $caption .= $captiondata['caption_text'];
     }
     // Source text
     if ($shortcode->has_flag('source-text', $atts) && !empty($captiondata['source_text'])) {
         // If the caption text is already part of the caption, we need to put a space before the source text
         if ($caption == $captiondata['caption_text']) {
             $caption .= ' ' . $captiondata['source_text'];
         } else {
             $caption .= $captiondata['source_text'];
         }
     }
     return $caption;
 }