Twitter\WordPress\Shortcodes\EmbeddedTweet::shortcodeHandler PHP Method

shortcodeHandler() public static method

Handle shortcode macro
Since: 1.0.0
public static shortcodeHandler ( array $attributes, string $content = '' ) : string
$attributes array set of shortcode attribute-value pairs or positional content matching the WordPress shortcode regex { @type string|int attribute name or positional int @type mixed shortcode value }
$content string content inside a shortcode macro. no effect on this shortcode
return string HTML markup. empty string if parameter requirement not met or no Tweet info found
    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);
        if (!$options['id']) {
            return '';
        }
        $tweet_id = $options['id'];
        unset($options['id']);
        $oembed_params = static::shortcodeParamsToOEmbedParams($tweet_id, $options);
        if (empty($oembed_params)) {
            return '';
        }
        // fetch HTML markup from Twitter oEmbed endpoint for the given parameters
        $html = trim(static::getOEmbedMarkup($oembed_params));
        if (!$html) {
            return '';
        }
        $html = '<div class="twitter-tweet">' . $html . '</div>';
        $inline_js = \Twitter\WordPress\JavaScriptLoaders\Widgets::enqueue();
        if ($inline_js) {
            return $html . $inline_js;
        }
        return $html;
    }