Skip to content

Instantly share code, notes, and snippets.

@jtsternberg
Last active May 23, 2016 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtsternberg/ace26c317c4d4a070abd to your computer and use it in GitHub Desktop.
Save jtsternberg/ace26c317c4d4a070abd to your computer and use it in GitHub Desktop.
basic usage for wds twitter widget (outside a widget)
<?php
wds_twwi_disable_widget_app_settings( array(
'consumer_key' => 'YOUR CONSUMER KEY',
'consumer_secret' => 'YOUR CONSUMER SECRET',
'access_token' => 'YOUR ACCESS TOKEN',
'access_token_secret' => 'YOUR ACCESS TOKEN SECRET',
) );
add_filter( 'wds_twwi_do_widget', '__return_false' );
function wds_get_tweets( $settings = array() ) {
$tw_app = TwitterWP::start()->get_app_creds();
$defaults = array(
'twitter_id' => '', // twitter username
'twitter_num' => 1, // number of tweets
'twitter_duration' => 60, // transient cache duration
'twitter_hide_replies' => 0, // Show user's @replies
'show_time_stamp' => 0, // Show tweet timestamp
'follow_link_show' => 0, // Show a 'follow user' link
'follow_link_text' => '', // Text for follow_link_show link
'consumer_key' => $tw_app[0], //
'consumer_secret' => $tw_app[1],
'access_token' => $tw_app[2],
'access_token_secret' => $tw_app[3],
);
$settings = wp_parse_args( $settings, $defaults );
return WDS_Twitter::get_tweets( $settings );
}
function wds_do_tweet( $settings = array() ) {
$tweets = wds_get_tweets( $settings );
foreach ( $tweets as $tweet ) {
echo $tweet;
}
}
@kellenmace
Copy link

kellenmace commented May 20, 2016

Or to have the plugin handle the output:

/**
 * Display WDS Twitter Widget
 */
function wds_display_twitter_widget() {

    if ( ! class_exists( 'WDS_Twitter' ) ) {
        return;
    }

    $settings = array(
        'twitter_id'           => '', // twitter username
        'twitter_num'          => 1,  // number of tweets
        'twitter_duration'     => 60, // transient cache duration
        'twitter_hide_replies' => 0,  // Show user's @replies
        'show_time_stamp'      => 0,  // Show tweet timestamp
        'follow_link_show'     => 0,  // Show a 'follow user' link
        'follow_link_text'     => '', // Text for follow_link_show link
        'consumer_key'         => 'YOUR CONSUMER KEY',
        'consumer_secret'      => 'YOUR CONSUMER SECRET',
        'access_token'         => 'YOUR ACCESS TOKEN',
        'access_token_secret'  => 'YOUR ACCESS TOKEN SECRET',
    );

    WDS_Twitter::tweets_list( $settings );
}

^ to return the output rather than echo it, change the last line to:
return WDS_Twitter::get_tweets_list( $settings );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment