public
Created

Updates to the twiter-cards WordPress plugin to include filters

  • Download Gist
twitter-cards.php.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
diff --git a/twitter-cards.php b/twitter-cards.php
index 06f6c00..6aa751c 100644
--- a/twitter-cards.php
+++ b/twitter-cards.php
@@ -22,9 +22,8 @@ class Twitter_Cards {
* @since 1.0
*/
public static function init() {
- if ( apply_filters( 'twitter_cards_display', is_single() ) ) {
+ if ( is_single() )
add_action( 'wp_head', 'Twitter_Cards::markup' );
- }
}
/**
@@ -38,45 +37,21 @@ class Twitter_Cards {
if ( ! class_exists( 'Twitter_Card_WP' ) )
require_once( dirname(__FILE__) . '/class-twitter-card-wp.php' );
- // Get Defaults
+ $card = new Twitter_Card_WP();
+ $card->setURL( apply_filters( 'rel_canonical', get_permalink() ) );
$post_type = get_post_type();
- $url = apply_filters( 'rel_canonical', get_permalink() );
- $title = ( post_type_supports( $post_type, 'title' ) ) ? get_the_title() : '';
- // one line, no HTML
- $description = ( post_type_supports( $post_type, 'excerpt' ) ) ? self::make_description( $post ) : '';
+ if ( post_type_supports( $post_type, 'title' ) )
+ $card->setTitle( get_the_title() );
+ if ( post_type_supports( $post_type, 'excerpt' ) ) {
+ // one line, no HTML
+ $card->setDescription( self::make_description( $post ) );
+ }
// does current post type and the current theme support post thumbnails?
if ( post_type_supports( $post_type, 'thumbnail' ) && function_exists( 'has_post_thumbnail' ) && has_post_thumbnail() ) {
list( $post_thumbnail_url, $post_thumbnail_width, $post_thumbnail_height ) = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
- $thumbnail = array(
- 'url' => $post_thumbnail_url,
- 'width' => $post_thumbnail_width,
- 'height' => $post_thumbnail_height
- );
+ $card->setImage( $post_thumbnail_url, $post_thumbnail_width, $post_thumbnail_height );
}
- // Apply Filters
- $url = apply_filters( 'twitter_cards_url', $url );
- $title = apply_filters( 'twitter_cards_title', $title );
- $description = apply_filters( 'twitter_cards_description', $description );
- $thumbnail = apply_filters( 'twitter_cards_thumbnail', $thumbnail );
- $site = apply_filters( 'twitter_cards_site', '' );
- $creator = apply_filters( 'twitter_cards_creator', '' );
-
- // Generate Card
- $card = new Twitter_Card_WP();
- if ( !empty($url) )
- $card->setURL( $url );
- if ( !empty($title) )
- $card->setTitle( $title );
- if ( !empty($description) )
- $card->setDescription( $description );
- if ( !empty($thumbnail) )
- $card->setImage( $thumbnail['url'], $thumbnail['width'], $thumbnail['height'] );
- if ( !empty($site) )
- $card->setSiteAccount( $site );
- if ( !empty($creator) )
- $card->setCreatorAccount( $creator );
-
if ( apply_filters( 'twitter_cards_htmlxml', 'html' ) === 'xml' )
echo $card->asXML();
else
\ No newline at end of file

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.