Exemplo n.º 1
0
function wpt_update_pro_settings()
{
    $message = '';
    if (isset($_POST['wpt_license_key'])) {
        $wpt_license_key = $_POST['wpt_license_key'];
        update_option('wpt_license_key', $wpt_license_key);
        if ($wpt_license_key != '') {
            $confirmation = wpt_check_license($wpt_license_key);
        } else {
            $confirmation = 'deleted';
        }
        $previously = get_option('wpt_license_valid');
        update_option('wpt_license_valid', $confirmation);
        if ($confirmation == 'inactive') {
            $message = __('Your WP Tweets PRO key was not activated.', 'wp-tweets-pro');
        } else {
            if ($confirmation == 'active' || $confirmation == 'valid') {
                $message = __('Your WP Tweets PRO key has been activated! Enjoy!', 'wp-tweets-pro');
            } else {
                if ($confirmation == 'deleted') {
                    $message = __('You have deleted your WP Tweets PRO license key.', 'wp-tweets-pro');
                } else {
                    if ($confirmation == 'invalid') {
                        if ($wpt_license_key != '') {
                            $message = sprintf(__('Your WP Tweets PRO license key is either expired or invalid. If expired, you can <a href="%s">renew now</a>.', 'wp-tweets-pro'), "https://www.joedolson.com/checkout/?edd_license_key={$wpt_license_key}&download_id=5729");
                        } else {
                            $message = sprintf(__('Your WP Tweets PRO license key is either expired or invalid. <a href="%s">Log in to your account to check</a>.', 'wp-tweets-pro'), "https://www.joedolson.com/account/");
                        }
                    } else {
                        $message = __('WP Tweets PRO received an unexpected message from the license server. Please try again!', 'wp-tweets-pro');
                    }
                }
            }
        }
        $notice = "<div id='message' class='updated notice'><p>{$message}</p></div>";
        echo $notice;
    }
    if (!empty($_POST['wp_pro_settings'])) {
        switch ($_POST['wp_pro_settings']) {
            case 'set':
                $wpt_delay_tweets = $_POST['wpt_delay_tweets'];
                $wpt_retweet_after = $_POST['wpt_retweet_after'];
                if (trim($wpt_delay_tweets) === '') {
                    $wpt_delay_tweets = 0;
                }
                if (trim($wpt_retweet_after) === '') {
                    $wpt_retweet_after = 0;
                }
                update_option('wpt_delay_tweets', $wpt_delay_tweets);
                update_option('wpt_retweet_after', $wpt_retweet_after);
                if ($wpt_delay_tweets > 0) {
                    update_option('wpt_tweet_remote', 0);
                }
                // remote posting is unnecessary with PRO activated.
                $wpt_retweet_repeat = $_POST['wpt_retweet_repeat'];
                update_option('wpt_retweet_repeat', $wpt_retweet_repeat);
                $wpt_custom_type = isset($_POST['wpt_custom_type']) ? $_POST['wpt_custom_type'] : 'prefix';
                $wpt_prepend_rt3 = isset($_POST['wpt_prepend_rt3']) ? $_POST['wpt_prepend_rt3'] : '';
                $wpt_prepend_rt2 = isset($_POST['wpt_prepend_rt2']) ? $_POST['wpt_prepend_rt2'] : '';
                $wpt_prepend_rt = isset($_POST['wpt_prepend_rt']) ? $_POST['wpt_prepend_rt'] : '';
                update_option('wpt_custom_type', $wpt_custom_type);
                update_option('wpt_prepend_rt', $wpt_prepend_rt);
                update_option('wpt_prepend_rt2', $wpt_prepend_rt2);
                update_option('wpt_prepend_rt3', $wpt_prepend_rt3);
                $wpt_rt_media = isset($_POST['wpt_rt_media']) ? 'true' : '';
                $wpt_rt_media2 = isset($_POST['wpt_rt_media2']) ? 'true' : '';
                $wpt_rt_media3 = isset($_POST['wpt_rt_media3']) ? 'true' : '';
                update_option('wpt_rt_media', $wpt_rt_media);
                update_option('wpt_rt_media2', $wpt_rt_media2);
                update_option('wpt_rt_media3', $wpt_rt_media3);
                $wpt_twitter_card = isset($_POST['wpt_twitter_card']) ? 1 : 0;
                update_option('wpt_twitter_card', $wpt_twitter_card);
                $wpt_twitter_card_type = isset($_POST['wpt_twitter_card_type']) ? $_POST['wpt_twitter_card_type'] : 'summary';
                update_option('wpt_twitter_card_type', $wpt_twitter_card_type);
                $wpt_toggle_card = isset($_POST['wpt_toggle_card']) ? (int) $_POST['wpt_toggle_card'] : 0;
                update_option('wpt_toggle_card', $wpt_toggle_card);
                $prepend = __('Warning: your Tweet re-posts are not differentiated. This may cause Twitter to block your re-posted Tweets.', 'wp-tweets-pro');
                $prepend_warning = '';
                if ($wpt_retweet_repeat == 1 && $wpt_prepend_rt == '') {
                    $prepend_warning = "{$prepend}";
                }
                if ($wpt_retweet_repeat == 2 && $wpt_prepend_rt2 == '') {
                    $prepend_warning = "{$prepend}";
                }
                if ($wpt_retweet_repeat == 3 && $wpt_prepend_rt3 == '') {
                    $prepend_warning = "{$prepend}";
                }
                $wpt_prepend = isset($_POST['wpt_prepend']) && $_POST['wpt_prepend'] == 'on' ? 1 : 0;
                update_option('wpt_prepend', $wpt_prepend);
                $wpt_filter_title = isset($_POST['wpt_filter_title']) && $_POST['wpt_filter_title'] == 'on' ? 1 : 0;
                $wpt_filter_post = isset($_POST['wpt_filter_post']) && $_POST['wpt_filter_post'] == 'on' ? 1 : 0;
                update_option('wpt_filter_title', $wpt_filter_title);
                update_option('wpt_filter_post', $wpt_filter_post);
                $wpt_blackout_from = isset($_POST['wpt_blackout_from']) ? (int) $_POST['wpt_blackout_from'] : 0;
                $wpt_blackout_to = isset($_POST['wpt_blackout_to']) ? (int) $_POST['wpt_blackout_to'] : 0;
                update_option('wpt_blackout', array('from' => $wpt_blackout_from, 'to' => $wpt_blackout_to));
                $wpt_media = isset($_POST['wpt_media']) && $_POST['wpt_media'] == 'on' ? 1 : 0;
                update_option('wpt_media', $wpt_media);
                $wpt_cotweet = isset($_POST['wpt_cotweet']) && $_POST['wpt_cotweet'] == 'on' ? 1 : 0;
                update_option('wpt_cotweet', $wpt_cotweet);
                $wpt_cotweet_lock = isset($_POST['wpt_cotweet_lock']) && $_POST['wpt_cotweet_lock'] != 'false' ? (int) $_POST['wpt_cotweet_lock'] : 'false';
                update_option('wpt_cotweet_lock', $wpt_cotweet_lock);
                if (isset($_POST['wpt_unschedule'])) {
                    wp_clear_scheduled_hook('wptcron');
                    $scheduled = wp_get_schedule('wptcron');
                    if ($scheduled) {
                        echo "<div class='updated error'><p>" . __('Automated Schedule was not cleared.', 'wp-tweets-pro') . "</p></div>";
                    } else {
                        delete_option('wpt_schedule');
                        echo "<div class='updated'><p>" . __('Automated Schedule Cleared', 'wp-tweets-pro') . "</p></div>";
                    }
                }
                $schedule = isset($_POST['wpt_schedule']) && $_POST['wpt_schedule'] != '' ? sanitize_text_field($_POST['wpt_schedule']) : false;
                $is_scheduled = isset($_POST['wpt_is_scheduled']) ? true : false;
                if ($schedule && !$is_scheduled) {
                    wpt_setup_schedules($schedule);
                }
                $schedule_template = isset($_POST['wpt_schedule_template']) ? $_POST['wpt_schedule_template'] : false;
                if ($schedule_template) {
                    update_option('wpt_schedule_template', $schedule_template);
                }
                $wpt_schedule_custom = isset($_POST['wpt_schedule_custom']) ? 'true' : 'false';
                update_option('wpt_schedule_custom', $wpt_schedule_custom);
                $wpt_autopost_notification = isset($_POST['wpt_autopost_notification']) ? $_POST['wpt_autopost_notification'] : false;
                if ($wpt_autopost_notification && is_email($wpt_autopost_notification)) {
                    update_option('wpt_autopost_notification', $wpt_autopost_notification);
                }
                $minimum_age = isset($_POST['wpt_minimum_age']) ? (int) $_POST['wpt_minimum_age'] : 15552000;
                // 180 days (~6 months)
                $maximum_age = isset($_POST['wpt_maximum_age']) ? (int) $_POST['wpt_maximum_age'] : 155520000;
                // 1800 days (~5 years)
                update_option('wpt_minimum_age', $minimum_age);
                update_option('wpt_maximum_age', $maximum_age);
                $wpt_autoretweet_post_types = isset($_POST['wpt_autoretweet_post_types']) ? $_POST['wpt_autoretweet_post_types'] : array();
                update_option('wpt_autoretweet_post_types', $wpt_autoretweet_post_types);
                // comment settings
                update_option('comment-published-text', isset($_POST['comment-published-text']) ? $_POST['comment-published-text'] : '');
                update_option('comment-published-update', isset($_POST['comment-published-update']) ? $_POST['comment-published-update'] : '');
                update_option('wpt_comment_delay', isset($_POST['wpt_comment_delay']) ? $_POST['wpt_comment_delay'] : '');
                $message = "<strong>" . __('WP Tweets PRO Settings Updated', 'wp-tweets-pro') . "</strong>";
                $notice = "<div id='message' class='updated notice'><p>{$message}</p></div>";
                if ($prepend_warning != '') {
                    $notice .= "<div id='message' class='error notice'><p>" . $prepend_warning . "</p></div>";
                }
                echo $notice;
                break;
        }
    }
}
Exemplo n.º 2
0
function wpt_update_pro_settings()
{
    $message = '';
    if (!empty($_POST['wp_pro_settings'])) {
        switch ($_POST['wp_pro_settings']) {
            case 'set':
                $wpt_delay_tweets = $_POST['wpt_delay_tweets'];
                $wpt_retweet_after = $_POST['wpt_retweet_after'];
                if (trim($wpt_delay_tweets) === '') {
                    $wpt_delay_tweets = 0;
                }
                if (trim($wpt_retweet_after) === '') {
                    $wpt_retweet_after = 0;
                }
                update_option('wpt_delay_tweets', $wpt_delay_tweets);
                update_option('wpt_retweet_after', $wpt_retweet_after);
                if ($wpt_delay_tweets > 0) {
                    update_option('jd_twit_remote', 0);
                }
                // remote posting is unnecessary with PRO activated.
                $wpt_retweet_repeat = $_POST['wpt_retweet_repeat'];
                update_option('wpt_retweet_repeat', $wpt_retweet_repeat);
                $wpt_license_key = $_POST['wpt_license_key'];
                update_option('wpt_license_key', $wpt_license_key);
                if ($wpt_license_key != '') {
                    $confirmation = wpt_check_license($wpt_license_key);
                } else {
                    $confirmation = 'deleted';
                }
                $previously = get_option('wpt_license_valid');
                update_option('wpt_license_valid', $confirmation);
                $wpt_custom_type = isset($_POST['wpt_custom_type']) ? $_POST['wpt_custom_type'] : 'prefix';
                $wpt_prepend_rt3 = isset($_POST['wpt_prepend_rt3']) ? $_POST['wpt_prepend_rt3'] : '';
                $wpt_prepend_rt2 = isset($_POST['wpt_prepend_rt2']) ? $_POST['wpt_prepend_rt2'] : '';
                $wpt_prepend_rt = isset($_POST['wpt_prepend_rt']) ? $_POST['wpt_prepend_rt'] : '';
                update_option('wpt_custom_type', $wpt_custom_type);
                update_option('wpt_prepend_rt', $wpt_prepend_rt);
                update_option('wpt_prepend_rt2', $wpt_prepend_rt2);
                update_option('wpt_prepend_rt3', $wpt_prepend_rt3);
                $wpt_twitter_card = isset($_POST['wpt_twitter_card']) ? 1 : 0;
                update_option('wpt_twitter_card', $wpt_twitter_card);
                $wpt_toggle_card = isset($_POST['wpt_toggle_card']) ? (int) $_POST['wpt_toggle_card'] : 0;
                update_option('wpt_toggle_card', $wpt_toggle_card);
                $prepend = __('Warning: your Tweet re-posts are not differentiated. This may cause Twitter to block your re-posted Tweets.', 'wp-tweets-pro');
                $prepend_warning = '';
                if ($wpt_retweet_repeat == 1 && $wpt_prepend_rt == '') {
                    $prepend_warning = "{$prepend}";
                }
                if ($wpt_retweet_repeat == 2 && $wpt_prepend_rt2 == '') {
                    $prepend_warning = "{$prepend}";
                }
                if ($wpt_retweet_repeat == 3 && $wpt_prepend_rt3 == '') {
                    $prepend_warning = "{$prepend}";
                }
                $wpt_prepend = isset($_POST['wpt_prepend']) && $_POST['wpt_prepend'] == 'on' ? 1 : 0;
                update_option('wpt_prepend', $wpt_prepend);
                $wpt_filter_title = isset($_POST['wpt_filter_title']) && $_POST['wpt_filter_title'] == 'on' ? 1 : 0;
                $wpt_filter_post = isset($_POST['wpt_filter_post']) && $_POST['wpt_filter_post'] == 'on' ? 1 : 0;
                update_option('wpt_filter_title', $wpt_filter_title);
                update_option('wpt_filter_post', $wpt_filter_post);
                $wpt_blackout_from = isset($_POST['wpt_blackout_from']) ? (int) $_POST['wpt_blackout_from'] : 0;
                $wpt_blackout_to = isset($_POST['wpt_blackout_to']) ? (int) $_POST['wpt_blackout_to'] : 0;
                update_option('wpt_blackout', array('from' => $wpt_blackout_from, 'to' => $wpt_blackout_to));
                $wpt_media = isset($_POST['wpt_media']) && $_POST['wpt_media'] == 'on' ? 1 : 0;
                update_option('wpt_media', $wpt_media);
                $wpt_cotweet = isset($_POST['wpt_cotweet']) && $_POST['wpt_cotweet'] == 'on' ? 1 : 0;
                update_option('wpt_cotweet', $wpt_cotweet);
                $wpt_cotweet_lock = isset($_POST['wpt_cotweet_lock']) && $_POST['wpt_cotweet_lock'] != 'false' ? (int) $_POST['wpt_cotweet_lock'] : 'false';
                update_option('wpt_cotweet_lock', $wpt_cotweet_lock);
                // comment settings
                update_option('comment-published-text', $_POST['comment-published-text']);
                update_option('comment-published-update', isset($_POST['comment-published-update']) ? $_POST['comment-published-update'] : "");
                if ($confirmation == 'false') {
                    $message = __('WP Tweets PRO key not valid.', 'wp-tweets-pro');
                } else {
                    if ($confirmation == 'inuse') {
                        $message = sprintf(__('WP Tweets PRO license key already registered. <a href="%s">Upgrade to a Developer\'s license!</a>', 'wp-tweets-pro'), 'http://www.joedolson.com/articles/account/');
                    } else {
                        if ($confirmation == 'unconfirmed') {
                            $message = __('Your payment for WP Tweets PRO has not been confirmed.', 'wp-tweets-pro');
                        } else {
                            if ($confirmation == 'true') {
                                if ($previously == 'true') {
                                } else {
                                    $message = __('WP Tweets PRO key validated. Enjoy!', 'wp-tweets-pro');
                                }
                            } else {
                                if ($confirmation == 'deleted') {
                                    $message = __('You have deleted your WP Tweets PRO license key.', 'wp-tweets-pro');
                                } else {
                                    $message = __('WP Tweets PRO received an unexpected message from the license server. Try again in a bit.', 'wp-tweets-pro');
                                }
                            }
                        }
                    }
                }
                $message = $message != '' ? "{$message} " : $message;
                // just add a space
                $message .= "<strong>" . __('WP Tweets PRO Settings Updated', 'wp-tweets-pro') . "</strong>";
                $notice = "<div id='message' class='updated notice'><p>{$message}</p></div>";
                if ($prepend_warning != '') {
                    $notice .= "<div id='message' class='error notice'><p>" . $prepend_warning . "</p></div>";
                }
                echo $notice;
                break;
        }
    }
}