Plugin is disabled and not visible on your website, some functions may not work if plugin is disabled.
');
}
settings_errors('updateSettings');
echo('
');
// outputs a unique nounce for our plugin options
settings_fields('dt_atp_plugin_settings');
// generates a unique hidden field with our form handling url
@do_settings_fields('dt_atp_plugin_settings');
if($options['dt_atp_textbox']){
$options['dt_atp_textbox'] = array_slice($options['dt_atp_textbox'], 0, 5);
}
$dt_atp_fields = count($options['dt_atp_textbox']) == 0 ? '1' : count($options['dt_atp_textbox']);
echo('
');
for ($i=1; $i < $dt_atp_fields; $i++){
echo('
'
);
}
echo('
');
// outputs the WP submit button html
@submit_button('Save Changes','primary','btnChange');
echo('
');
echo('
');
// outputs a unique nounce for our plugin options
settings_fields('dt_atp_plugin_additional_settings');
// generates a unique hidden field with our form handling url
@do_settings_fields('dt_atp_plugin_additional_settings');
echo('
Number of tweets you want to get per username/hashtag per API Call. IMPORTANT: Limit is 180 API Calls, one API Call equals 15 Tweets. SUGGESTION: for 5 hashtags/usernames, maximum is 165 tweets every 5 minutes.
Number of tweets you want to save and show on your website, some functions may not work if plugin is disabled. IMPORTANT: Higher the number, higher is the loading time of your website, some functions may not work if plugin is disabled. SUGGESTION: Limit to 200-300 Tweets, no one wants to scroll forever.
minutes
How offten to collect new Tweets, you have to active this option in Dashboard. IMPORTANT: There is a limit, combine it with "Number of Tweets" from above. SUGGESTION: If you have 5 hashtags/usernames and you left Number of Tweets on 165, leave this at default value ( 5 minutes ).
WP Cron activates every X minutes if you have a visitor, if you don\'t have high traffic you should add your website to cronjob.
');
echo('
');
// outputs the WP submit button html
@submit_button();
echo('
');
}
// 8.3
// hint: twitter settings
function dt_atp_twitter_settings_admin_page() {
// get the default values for our options
$options = dt_atp_get_current_options('twitter');
echo('
Plugin is disabled and not visible on your website, some functions may not work if plugin is disabled.
');
}
echo('
This is the page where you enter details about your Twitter Application
IMPORTANT: If you don\'t know how to make your twitter application, check our instructions under the form.
');
// outputs a unique nounce for our plugin options
settings_fields('dt_atp_plugin_twitter');
// generates a unique hidden field with our form handling url
@do_settings_fields('dt_atp_plugin_twitter');
echo('
');
// outputs the WP submit button html
@submit_button();
echo('
Description: You don’t have to worry much about the description- you can change this later.
Website: Put your website in the website field. It’s supposed to be your application’s publicly accessible home page.
Callback URL: You can ignore the Callback URL field.
You’ll then be presented with lots of information, but we’re not quite done yet. We now need to authorise the Twitter app for your Twitter account. To do this, click the “Create my access token” button. This takes a few seconds, so if you don’t see the access tokens on the next screen, you may have to refresh the page a few times.
Once you’ve done this, you can copy your Consumer Key, Consumer Secret, OAuth Access Token, OAuth Access Token Secret to form above.
Plugin is disabled and not visible on your website, some functions may not work if plugin is disabled.
');
}
echo('
You can customize your format as you wish, you can see simple example in textarea, hover over buttons for description IMPORTANT: Use only twitter option from buttons above textarea, custom options won\'t work.
Format your Tweets
');
// outputs a unique nounce for our plugin options
settings_fields('dt_atp_display_style');
// generates a unique hidden field with our form handling url
@do_settings_fields('dt_atp_display_style');
echo('Atributes from Twitter:
Add class to wrapper div:
');
@submit_button();
echo('Want to make it look better? add "scroll" class to wrapper and define it in your css as: .scroll {
overflow: scroll;
max-height: 410px;
}
');
}
/* !9. SETTINGS */
// 9.1
// hint: registers all our plugin options
function dt_atp_register_twitter() {
// plugin options
register_setting('dt_atp_plugin_twitter', 'dt_atp_customer_key','dt_atp_validate_plugin');
register_setting('dt_atp_plugin_twitter', 'dt_atp_customer_secret','dt_atp_validate_plugin');
register_setting('dt_atp_plugin_twitter', 'dt_atp_access_token','dt_atp_validate_plugin');
register_setting('dt_atp_plugin_twitter', 'dt_atp_access_token_secret','dt_atp_validate_plugin');
}
function dt_atp_register_settings() {
// plugin options
register_setting('dt_atp_plugin_settings', 'dt_atp_textbox','dt_atp_validation_function');
register_setting('dt_atp_plugin_settings', 'dt_atp_radio','dt_atp_validate_wp_cron_again');
if(isset($_POST['btnChange'])){
$type = 'notice-warning';
$message = __( 'After changing hashtags or usernames we suggest you go to Dashboard and reset old tweets.');
add_settings_error(
'updateSettings',
esc_attr( 'settings_updated' ),
$message,
$type
);
}
}
function dt_atp_register_additional_settings(){
register_setting('dt_atp_plugin_additional_settings', 'dt_atp_number_of_saved_tweets');
register_setting('dt_atp_plugin_additional_settings', 'dt_atp_cron_time');
register_setting('dt_atp_plugin_additional_settings', 'dt_atp_number_of_tweets','dt_atp_validate_wp_cron');
}
function dt_atp_register_dashboard_form1(){
register_setting('dt_atp_dashboard_form1', 'dt_atp_status_enabled','dt_atp_validate_status');
}
function dt_atp_register_dashboard_form2(){
register_setting('dt_atp_dashboard_form2', 'dt_atp_wp_cron_enabled','dt_atp_validate_status_settings');
}
function dt_atp_register_display_style(){
register_setting('dt_atp_display_style', 'dt_atp_textarea_style');
register_setting('dt_atp_display_style', 'dt_atp_wrapper_class');
}
/* !10. MISCELLANEOUS */
//if hashtag/username field empty don't save it
function dt_atp_validation_function( $input ) {
$input = array_filter($input);
return $input;
}
//if twitter information empty don't allow plugin to be enabled
function dt_atp_validate_status( $input ) {
if($input == 1){
$options = dt_atp_get_current_options('twitter');
if(empty($options) || empty($options['dt_atp_customer_secret']) || empty($options['dt_atp_access_token']) || empty($options['dt_atp_access_token_secret']) || empty($options['dt_atp_customer_key'])){
return add_settings_error(
'TwitterError',
esc_attr( 'check_status' ),
'You can\'t enable plugin if you did not add Twitter App information, you can do that here.',
'notice-warning'
);
}
}
return $input;
}
// if twitter information empty disable plugin
function dt_atp_validate_plugin( $input ) {
if(empty($input)){
update_option('dt_atp_status_enabled',0);
}else {
return $input;
}
}
// if wp cron settings pass limit, don't allow it
function dt_atp_validate_wp_cron( $input ) {
$time = floor(15 / get_option('dt_atp_cron_time',5));
$calls = ceil ($input/15);
$time = $calls * count(get_option('dt_atp_textbox')) * $time;
if($time > 179){
add_settings_error(
'updateSettings',
esc_attr( 'settings_updated' ),
'Your current settings pass Limit of 180 API Calls, decrease number of Tweets or increase time of WP Cron.',
'error'
);
return 29;
}
else{
return $input;
}
}
function dt_atp_validate_wp_cron_again( $input ) {
$time = floor(15 / get_option('dt_atp_cron_time',5));
$calls = ceil (get_option('dt_atp_number_of_tweets')/15);
$time = $calls * count(get_option('dt_atp_textbox')) * $time;
if($time > 179){
add_settings_error(
'updateSettings',
esc_attr( 'settings_updated' ),
'Your current settings pass Limit of 180 API Calls, decrease number of Tweets or increase time of WP Cron.',
'error'
);
update_option('dt_atp_number_of_tweets',29);
}
return $input;
}
//if twitter information empty and/or plugin disabled, don't allow wp cron
function dt_atp_validate_status_settings( $input ) {
if(get_option('dt_atp_status_enabled') == 1){
if(count(get_option('dt_atp_textbox')) > 0){
return dt_atp_validate_status( $input );
}else{
return add_settings_error(
'TwitterError',
esc_attr( 'check_status' ),
'You have to add hashtag/username here',
'notice-error'
);
}
}
else{
return add_settings_error(
'TwitterError',
esc_attr( 'check_status' ),
'You have to enable plugin.',
'notice-warning'
);
}
}
//get the last time json was modified
function dt_atp_last_update_time(){
$time = get_option('dt_atp_last_update_time');
if ($time) {
$time = time() - $time;
$time = ($time<1)? 1 : $time;
$tokens = array (
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
foreach ($tokens as $unit => $text) {
if ($time < $unit) continue;
$numberOfUnits = floor($time / $unit);
return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s ':'').' ago';
}
}
else {
return 'Never';
}
}
// reset json and last ids
function dt_atp_reset_tweets(){
if(isset($_POST['btnReset'])){
file_put_contents(dt_atp_plugin_dir.'twitter.json', json_encode(new stdClass));
update_option('dt_atp_last_update_time',time());
update_option('dt_atp_currently_active','');
}
$red = ($_SERVER["HTTP_REFERER"] != '' ? $_SERVER["HTTP_REFERER"] : site_url());
header("Location: " . $red);
exit;
}
// SCHEDULE 'WP CRON' if you can call it that way
if ( ! get_transient( 'schedule' ) && get_option('dt_atp_wp_cron_enabled')) {
set_transient( 'schedule', true, get_option('dt_atp_cron_time') * MINUTE_IN_SECONDS );
dt_atp_get_new_tweets();
}
function dt_atp_uninstall_plugin() {
$options = array();
$options['dt_atp_plugin_twitter'] = array('dt_atp_customer_key', 'dt_atp_customer_secret', 'dt_atp_access_token', 'dt_atp_access_token_secret');
$options['dt_atp_plugin_settings'] = array('dt_atp_textbox', 'dt_atp_radio');
$options['dt_atp_plugin_additional_settings'] = array('dt_atp_number_of_saved_tweets', 'dt_atp_cron_time', 'dt_atp_number_of_tweets');
$options['dt_atp_dashboard_form1'] = array('dt_atp_status_enabled');
$options['dt_atp_dashboard_form2'] = array('dt_atp_wp_cron_enabled');
$options['dt_atp_display_style'] = array('dt_atp_textarea_style', 'dt_atp_wrapper_class');
// loop over all the settings
foreach( $options as $g=>$k ):
foreach($k as $s){
unregister_setting( $g, $s );
delete_option($s);
}
endforeach;
delete_option( 'dt_atp_currently_active' );
delete_option( 'dt_atp_last_update_time' );
return true;
}