コード例 #1
0
ファイル: PeriscopeOnAir.php プロジェクト: cemoulto/wordpress
 /**
  * Handle shortcode macro
  *
  * @since 1.3.0
  *
  * @param array  $attributes shortcode attributes
  * @param string $content    shortcode content. no effect
  *
  * @return string Periscope On Air button HTML or empty string
  */
 public static function shortcodeHandler($attributes, $content = '')
 {
     // clean up attribute to shortcode option mappings before passing to filter
     // apply the same filter as shortcode_atts
     /** This filter is documented in wp-includes/shortcodes.php */
     $options = apply_filters('shortcode_atts_' . self::SHORTCODE_TAG, array_merge(static::$SHORTCODE_DEFAULTS, static::sanitizeShortcodeParameters((array) $attributes)), static::$SHORTCODE_DEFAULTS, $attributes);
     $username = '';
     if (isset($options['username'])) {
         $username = $options['username'];
         unset($options['username']);
     }
     if (!$username) {
         $username = static::getUsername();
         // user target required
         if (!$username) {
             return '';
         }
     }
     // update the options array with the Periscope username
     $options['username'] = $username;
     unset($username);
     $on_air = \Twitter\Widgets\PeriscopeOnAir::fromArray($options);
     if (!$on_air) {
         return '';
     }
     $html = $on_air->toHTML('\\Twitter\\WordPress\\Helpers\\HTMLBuilder');
     if (!$html) {
         return '';
     }
     $html = '<div class="periscope-on-air">' . $html . '</div>';
     $inline_js = \Twitter\WordPress\JavaScriptLoaders\Widgets::enqueue();
     if ($inline_js) {
         return $html . $inline_js;
     }
     return $html;
 }
コード例 #2
0
 /**
  * Update a widget instance
  *
  * @since 1.3.0
  *
  * @param array $new_instance New settings for this instance as input by the user via form()
  * @param array $old_instance Old settings for this instance
  *
  * @return bool|array settings to save or false to cancel saving
  */
 public function update($new_instance, $old_instance)
 {
     $instance = array();
     $new_instance = (array) $new_instance;
     $title = trim(strip_tags($new_instance['title']));
     if ($title) {
         $instance['title'] = $title;
     }
     unset($new_instance['title']);
     $on_air = \Twitter\Widgets\PeriscopeOnAir::fromArray($new_instance);
     if (!$on_air) {
         return false;
     }
     $filtered_options = $on_air->toArray();
     $username = $on_air->getUsername();
     if ($username) {
         $filtered_options['username'] = $username;
     }
     unset($username);
     return array_merge($instance, $filtered_options);
 }
コード例 #3
0
ファイル: PeriscopeOnAir.php プロジェクト: cemoulto/wordpress
 /**
  * Test setting size from an options array
  *
  * @since 1.3.0
  *
  * @covers ::fromArray
  * @small
  *
  * @dataProvider sizeProvider
  *
  * @param string $size size
  * @param bool $expected_valid is the passed size expected to pass?
  * @param string $message error message
  *
  * @return void
  */
 public function testsetSizeFromOptionsArray($size, $expected_valid, $message = '')
 {
     $options = self::optionsArraySetUp();
     $options['size'] = $size;
     $this->button = \Twitter\Widgets\PeriscopeOnAir::fromArray($options);
     $this->assertNotNull($this->button);
     $this->setSizeResult($size, $expected_valid, $message);
 }