Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
Remove the Tweet Button extension
Browse files Browse the repository at this point in the history
The share button shortcodes should never have been in the theme in the
first place.

The Twitter share button now uses an anchor link and javascript instead
of the PHP version or an iframe.
  • Loading branch information
jayj committed Jul 7, 2013
1 parent 74cb15e commit 93d0a05
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 208 deletions.
4 changes: 0 additions & 4 deletions functions.php
Expand Up @@ -80,7 +80,6 @@ function cakifo_theme_setup() {

add_theme_support( 'cakifo-shortcodes' );
add_theme_support( 'cakifo-colorbox' );
add_theme_support( 'cakifo-twitter-button' );

/* Load Theme Settings */
if ( is_admin() ) {
Expand Down Expand Up @@ -288,9 +287,6 @@ function cakifo_load_theme_support() {

/* Load the Colorbox Script extention if supported. */
require_if_theme_supports( 'cakifo-colorbox', $template_directory . 'functions/colorbox.php' );

/* Load the Twitter Button extention if supported */
require_if_theme_supports( 'cakifo-twitter-button', $template_directory . 'functions/tweet_button.php' );
}

add_action( 'after_setup_theme', 'cakifo_load_theme_support', 12 );
Expand Down
73 changes: 31 additions & 42 deletions functions/shortcodes.php
Expand Up @@ -166,55 +166,44 @@ function cakifo_entry_facebook_link_shortcode( $attr ) {
* @since Cakifo 1.0.0
*/
function cakifo_entry_twitter_link_shortcode( $attr ) {

static $first = true;

$attr = shortcode_atts( array(
'href' => get_permalink(),
'text' => the_title_attribute( 'echo=0' ),
'layout' => 'horizontal', // horizontal, vertical, none
'via' => hybrid_get_setting( 'twitter_username' ),
'width' => 55, // Only need to use if there's no add_theme_support( 'cakifo-twitter-button' )
'height' => 20, // Only need to use if there's no add_theme_support( 'cakifo-twitter-button' )
'layout' => 'horizontal', // horizontal, vertical, non
'via' => '',
'before' => '',
'after' => '',
), $attr, 'entry-twitter-link' );

/* Load the PHP tweet button script if the theme supports it */
if ( current_theme_supports( 'cakifo-twitter-button' ) ) :

return cakifo_tweet_button(
array(
'before' => $attr['before'],
'after' => $attr['after'],
'layout' => $attr['layout'],
'href' => $attr['href'],
'counturl' => $attr['href'],
'text' => $attr['text'],
'layout' => $attr['layout'],
'via' => $attr['via']
)
);

/* Else, load the Twitter iframe */
else :

// Set the height to 62px if the layout is vertical and the height is the default value
if ( 'vertical' == $attr['layout'] && 20 == $attr['height'] )
$attr['height'] = 62;

// Set width to 110px if the layout is horizontal and the width is the default value
if ( 'horizontal' == $attr['layout'] && 55 == $attr['width'] )
$attr['width'] = 110;

// Build the query
$query_args = array(
'url' => esc_url( $attr['href'] ),
'via' => esc_attr( $attr['via'] ),
'text' => esc_attr( $attr['text'] ),
'count' => esc_attr( $attr['layout'] )
);

return $attr['before'] . '<iframe src="http://platform.twitter.com/widgets/tweet_button.html?' . http_build_query( $query_args, '', '&amp;' ) . '" class="twitter-share-button" style="width:' . intval( $attr['width'] ) . 'px; height:' . intval( $attr['height'] ) . 'px;" seamless></iframe>' . $attr['after'];

endif;
// Only add the script once
$script = ( $first ) ? "<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>" : "";

$first = false;

// Build the query
$query_args = array(
'url' => esc_url( $attr['href'] ),
'counturl' => esc_url( $attr['href'] ),
'text' => esc_attr( $attr['text'] ),
'count' => esc_attr( $attr['layout'] ),
);

/* Use the shortlink as the share URL if it exists. */
$shortlink = wp_get_shortlink();

if ( ! empty( $shortlink ) ) {
$query_args['url'] = esc_url( $shortlink );
}

/* Set 'via' attribute. */
if ( ! empty( $attr['via'] ) ) {
$query_args['via'] = esc_attr( $attr['via'] );
}

return $attr['before'] . '<a href="https://twitter.com/share?' . http_build_query( $query_args, '', '&amp;' ) . '" class="twitter-share-button"></a>' . $attr['after'] . $script;
}

/**
Expand Down
162 changes: 0 additions & 162 deletions functions/tweet_button.php

This file was deleted.

0 comments on commit 93d0a05

Please sign in to comment.