/** * Link to a site's Twitter profile using rel me * * Adds via attribution to Twitter widgets on the page * * @link http://microformats.org/wiki/rel-me XFN rel me * * @return void */ public static function relMe() { $site_username = \Twitter\WordPress\Site\Username::getViaAttribution(in_the_loop() ? get_the_ID() : null); if ($site_username) { echo '<link rel="me" href="' . esc_url(\Twitter\Helpers\TwitterURL::profile($site_username), array('https', 'http')) . '"' . \Twitter\WordPress\Helpers\HTMLBuilder::closeVoidHTMLElement() . '>'; } }
/** * Handle shortcode macro * * @since 1.0.0 * * @param array $attributes shortcode attributes * @param string $content shortcode content. no effect * * @return string Tweet button HTML or empty string */ 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\TweetButton::fromArray($options); if (!$button) { return ''; } $html = $button->toHTML(_x('Tweet', 'Tweet verb. Sharing.', 'twitter'), '\\Twitter\\WordPress\\Helpers\\HTMLBuilder'); if (!$html) { return ''; } \Twitter\WordPress\JavaScriptLoaders\Widgets::enqueue(); return '<div class="twitter-share">' . $html . '</div>'; }
/** * Add site attibution to the passed card if a Twitter username is stored for the current site * * @since 1.0.0 * * @param \Twitter\Cards\Card $card Twitter Card object * @param int|string $post_id WP_Post->ID or proprietary post identifier * * @return \Twitter\Cards\Card Twitter Card object */ public static function addSiteAttribution($card, $post_id = null) { if (!is_a($card, '\\Twitter\\Cards\\Card')) { return; } if (!method_exists($card, 'setSite')) { return $card; } $site_username = \Twitter\WordPress\Site\Username::getSiteAttribution($post_id); if ($site_username) { $card->setSite(\Twitter\Cards\Components\Account::fromScreenName($site_username)); } return $card; }