forked from stormuk/storm-twitter-for-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter-feed-for-developers-settings.php
78 lines (59 loc) · 3.23 KB
/
twitter-feed-for-developers-settings.php
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
72
73
74
75
76
77
78
<?php
//Add an option page
if (is_admin()) {
add_action('admin_menu', 'tdf_menu');
add_action('admin_init', 'tdf_register_settings');
}
function tdf_menu() {
add_options_page('Twitter Feed for Developers','Twitter Feed Auth','manage_options','tdf_settings','tdf_settings_output');
}
function tdf_settings() {
$tdf = array();
$tdf[] = array('name'=>'tdf_consumer_key','label'=>'Twitter Application Consumer Key');
$tdf[] = array('name'=>'tdf_consumer_secret','label'=>'Twitter Application Consumer Secret');
$tdf[] = array('name'=>'tdf_access_token','label'=>'Account Access Token');
$tdf[] = array('name'=>'tdf_access_token_secret','label'=>'Account Access Token Secret');
$tdf[] = array('name'=>'tdf_cache_expire','label'=>'Cache Duration (Default 3600)');
$tdf[] = array('name'=>'tdf_user_timeline','label'=>'Twitter Feed Screen Name*');
return $tdf;
}
function tdf_register_settings() {
$settings = tdf_settings();
foreach($settings as $setting) {
register_setting('tdf_settings',$setting['name']);
}
}
function tdf_settings_output() {
$settings = tdf_settings();
echo '<div class="wrap">';
echo '<h2>oAuth Twitter Feed for Developers</h2>';
echo '<p>Most of this configuration can found on the application overview page on the <a href="http://dev.twitter.com/apps">http://dev.twitter.com</a> website.</p>';
echo '<p>When creating an application for this plugin, you don\'t need to set a callback location and you only need read access.</p>';
echo '<p>You will need to generate an oAuth token once you\'ve created the application. The button for that is on the bottom of the application overview page.</p>';
echo '<p>Once configured, you then need to call getTweets() anywhere in your template. getTweets supports 3 parameters - the number of tweets to load (max 20), the username of the twitter feed you want to load, and any additional parameters you want to send to Twitter. An example code usage is shown under the debug information below.</p>';
echo '<p>The format of the response from getTweets will either be an array of arrays containing tweet objects, as described on the official Twitter documentation <a href="https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline">here</a>, or an 1D array containing an "error" key, with a value of the error that occurred.</p>';
echo '<hr />';
echo '<form method="post" action="options.php">';
settings_fields('tdf_settings');
echo '<table>';
foreach($settings as $setting) {
echo '<tr>';
echo '<td>'.$setting['label'].'</td>';
echo '<td><input type="text" style="width: 400px" name="'.$setting['name'].'" value="'.get_option($setting['name']).'" /></td>';
echo '</tr>';
if ($setting['name'] == 'tdf_user_timeline') {
echo '<tr>';
echo '<td colspan="2" style="font-size:10px; font-style: italic">This option is no longer required. You may define the screen name to load as part of the getTweets() call as detailed above.</td>';
echo '</tr>';
}
}
echo '</table>';
submit_button();
echo '</form>';
echo '<hr />';
echo '<h3>Debug Information</h3>';
$last_error = get_option('tdf_last_error');
if (empty($last_error)) $last_error = "None";
echo 'Last Error: '.$last_error.'</p>';
echo '</div>';
}