shortcodeHandler() public static method

Handle shortcode macro
Since: 1.0.0
public static shortcodeHandler ( array $attributes, string $content = null ) : string
$attributes array shortcode attributes
$content string shortcode content. no effect
return string Tweet button HTML or empty string
Esempio n. 1
0
 /**
  * Filter the_content, possibly adding Tweet button(s)
  *
  * @since 1.0.0
  *
  * @param string $content content of the current post
  *
  * @return string $content content of the current post, possibly with Tweet button markup added
  */
 public static function contentFilter($content)
 {
     // do not include Tweet button(s) in an autogenerated excerpt
     // get_the_excerpt filter calls wp_trim_excerpt() at priority 10 which triggers the_content filter on an empty excerpt string
     if (doing_filter('get_the_excerpt')) {
         return $content;
     }
     $options = static::getOption();
     if (isset($options['position'])) {
         $position = $options['position'];
         unset($options['position']);
         $tweet_button = \Twitter\WordPress\Shortcodes\Share::shortcodeHandler($options);
         if ($tweet_button) {
             // wrap in newlines to preserve content scanners looking for adjacent content on its own line
             $tweet_button = "\n" . $tweet_button . "\n";
             if ('before' === $position) {
                 return $tweet_button . $content;
             } else {
                 if ('after' === $position) {
                     return $content . $tweet_button;
                 } else {
                     if ('both' === $position) {
                         return $tweet_button . $content . $tweet_button;
                     }
                 }
             }
         }
     }
     return $content;
 }