-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate the wordpress functionality into its own file, and included …
…it via the 'files' autoload.
- Loading branch information
Showing
3 changed files
with
113 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
|
||
/************************************ | ||
wordpress functionality | ||
***********************************/ | ||
|
||
// check if we're inside wordpress | ||
if ( function_exists( 'add_shortcode' ) ) { | ||
|
||
// twitter aggregator options for the wordpress settings page and the shortcode | ||
$ta_options = array( | ||
'ta_consumer_key', | ||
'ta_consumer_secret', | ||
'ta_oauth_access_token', | ||
'ta_oauth_access_token_secret', | ||
'ta_usenames' | ||
); | ||
|
||
|
||
/************************************ | ||
shortcode [twitter-aggregator] | ||
***********************************/ | ||
function twitter_aggregator_shortcode( $atts ) { | ||
|
||
// default parameters | ||
$a = shortcode_atts( array( | ||
'consumer_key' => get_option( "ta_consumer_key", "" ), | ||
'consumer_secret' => get_option( "ta_consumer_secret", "" ), | ||
'oauth_access_token' => get_option( "ta_oauth_access_token", "" ), | ||
'oauth_access_token_secret' => get_option( "ta_oauth_access_token_secret", "" ), | ||
'usernames' => get_option( "ta_usenames", "reuters,ap,propublica" ), | ||
'update_interval' => 10, | ||
'styles' => true, | ||
'count' => 10, | ||
'exclude_replies' => true, | ||
'include_rts' => true | ||
), $atts ); | ||
|
||
|
||
// generate an aggregator object | ||
$ta = new twitterAggregator( $a ); | ||
|
||
if ( $a['styles'] ) { | ||
// display the widget | ||
return $ta->widget(); | ||
} else { | ||
// display the widget | ||
return $ta->widget_unstyled(); | ||
} | ||
} | ||
|
||
// register our function as a shortcode | ||
add_shortcode( 'twitter-aggregator', 'twitter_aggregator_shortcode' ); | ||
|
||
|
||
|
||
/************************************ | ||
settings interface | ||
***********************************/ | ||
|
||
// register the settings for the first time. | ||
function ta_register_settings() { | ||
global $ta_options; | ||
|
||
// loop through the options and add them. | ||
foreach ( $ta_options as $opt ) { | ||
add_option( $opt, ''); | ||
register_setting( 'ta_options_group', $opt ); | ||
} | ||
} | ||
add_action( 'admin_init', 'ta_register_settings' ); | ||
|
||
|
||
// register the options page in the admin menu | ||
function ta_register_options_page() { | ||
add_options_page('Twitter Aggregator Settings', 'Twitter Aggregator', 'manage_options', 'ta', 'ta_options_page'); | ||
} | ||
add_action('admin_menu', 'ta_register_options_page'); | ||
|
||
|
||
// the actual page output function | ||
function ta_options_page() { | ||
global $ta_options; | ||
|
||
?> | ||
<h2>Twitter Aggregator Settings</h2> | ||
<form method="post" action="options.php"> | ||
<?php | ||
|
||
// settings field group | ||
settings_fields( 'ta_options_group' ); | ||
|
||
// loop through the options and output fields. | ||
foreach ( $ta_options as $opt ) { | ||
?> | ||
<p><label for="<?php print $opt ?>"><?php print ucwords( str_replace( "ta_", "", str_replace( "_", " ", $opt ) ) ); ?></label><br> | ||
<input type="text" id="<?php print $opt; ?>" name="<?php print $opt; ?>" value="<?php echo get_option( $opt ); ?>" /></p> | ||
<?php | ||
} | ||
|
||
// add the submit button. | ||
submit_button(); | ||
|
||
?> | ||
</form> | ||
<?php | ||
} | ||
|
||
} | ||
|