public static function shortcodeHandler($attributes, $content = null)
{
// 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);
// add options shared to post meta
$options = static::addPostMetaOptions($options);
// add parameters based on per-post render context
if (in_the_loop()) {
$post = get_post();
// do not share posts requiring a password to access
if ($post && !empty($post->post_password)) {
return '';
}
// protect sites from themselves
// do not display Tweet button for non-public content to avoid leaking content
$post_status_object = get_post_status_object(get_post_status($post));
if (!($post_status_object && isset($post_status_object->public) && $post_status_object->public)) {
return '';
}
unset($post_status_object);
// add parameters based on post data
$options = static::addPostData($options, $post);
unset($post);
}
if (!(isset($options['via']) && $options['via'])) {
// attribute the Tweet to the site Twitter username
$via_username = \Twitter\WordPress\Site\Username::getViaAttribution(in_the_loop() ? get_the_ID() : null);
if ($via_username) {
$options['via'] = $via_username;
}
unset($via_username);
}
$button = \Twitter\Widgets\Buttons\Tweet::fromArray($options);
if (!$button) {
return '';
}
$html = $button->toHTML(_x('Tweet', 'Tweet verb. Sharing.', 'twitter'), '\\Twitter\\WordPress\\Helpers\\HTMLBuilder');
if (!$html) {
return '';
}
$html = '<div class="twitter-share">' . $html . '</div>';
$inline_js = \Twitter\WordPress\JavaScriptLoaders\Widgets::enqueue();
if ($inline_js) {
return $html . $inline_js;
}
return $html;
}