Since: 1.0.0
Inheritance: implements Twitter\WordPress\Shortcodes\ShortcodeInterface
Example #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;
 }
Example #2
0
 /**
  * Test setting Tweet button sizes from a shortcode attribute
  *
  * @since 1.0.0
  *
  * @covers ::sanitizeShortcodeParameters
  * @small
  *
  * @dataProvider sizeProvider
  *
  * @param string $size           button size configuration
  * @param bool   $expected_valid expected validity
  * @param string $message        error message to display on negative assertion
  *
  * @return void
  */
 public function testSanitizeShortcodeParametersSize($size, $expected_valid, $message = '')
 {
     $options = \Twitter\WordPress\Shortcodes\Share::sanitizeShortcodeParameters(array('size' => $size));
     if ($expected_valid) {
         $this->assertTrue(isset($options['size']) && $options['size'] === 'large', $message);
     } else {
         $this->assertEmpty($options, $message);
     }
 }