Twitter\WordPress\Shortcodes\PeriscopeOnAir::shortcodeHandler PHP Méthode

shortcodeHandler() public static méthode

Handle shortcode macro
Since: 1.3.0
public static shortcodeHandler ( array $attributes, string $content = '' ) : string
$attributes array shortcode attributes
$content string shortcode content. no effect
Résultat 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\Buttons\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;
    }

Usage Example

Exemple #1
0
 /**
  * Front-end display of widget
  *
  * @since 1.3.0
  *
  * @param array $args     Display arguments including before_title, after_title, before_widget, and after_widget.
  * @param array $instance The settings for the particular instance of the widget
  *
  * @return void
  */
 public function widget($args, $instance)
 {
     $button_html = \Twitter\WordPress\Shortcodes\PeriscopeOnAir::shortcodeHandler($instance);
     if (!$button_html) {
         return;
     }
     /** This filter is documented in wp-includes/default-widgets.php */
     $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
     unset($instance['title']);
     echo $args['before_widget'];
     if ($title) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     // escaped in markup builder
     // @codingStandardsIgnoreStart WordPress.XSS.EscapeOutput
     echo $button_html;
     // @codingStandardsIgnoreEnd WordPress.XSS.EscapeOutput
     echo $args['after_widget'];
 }