<?php
/**
* Manage XPoster Pro Settings
*
* @category Core
* @package XPoster Pro
* @author Joe Dolson
* @license GPLv2 or later
* @link https://www.xposterpro.com
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'admin_menu', 'wpt_pro_menu' );
/**
* Add XPoster Pro admin menu
*/
function wpt_pro_menu() {
global $user_ID;
/**
* Filter the users allowed to see the XPoster Pro admin pages.
*
* @hook wpt_main_settings
*
* @param {string} $allowed_group WordPress capability.
* @param {int} $user_ID Current user ID.
*
* @return {string}
*/
$allowed_group = apply_filters( 'wpt_main_settings', 'manage_options', $user_ID );
$icon_path = plugins_url( 'images/logo-white.png', __FILE__ );
if ( function_exists( 'add_menu_page' ) ) {
$function = ( function_exists( 'wpt_tweet' ) ) ? 'wpt_update_settings' : 'wpt_warning';
$page = add_menu_page( __( 'XPoster Pro', 'wp-tweets-pro' ), __( 'XPoster Pro', 'wp-tweets-pro' ), $allowed_group, 'wp-tweets-pro', $function, $icon_path );
if ( function_exists( 'wpt_tweet' ) ) {
add_action( 'admin_head-' . $page, 'wpt_admin_style' );
}
}
if ( function_exists( 'add_submenu_page' ) ) {
/**
* Filter the users allowed to see the XPoster Pro scheduled Tweets screen.
*
* @hook wpt_scheduled_tweets_capability
*
* @param {string} $allowed_group WordPress capability.
* @param {int} $user_ID Current user ID.
*
* @return {string}
*/
$scheduled_permissions = apply_filters( 'wpt_scheduled_tweets_capability', 'manage_options', $user_ID );
/**
* Filter the users allowed to see the XPoster Pro past Tweets screen.
*
* @hook wpt_past_tweets_capability
*
* @param {string} $allowed_group WordPress capability.
* @param {int} $user_ID Current user ID.
*
* @return {string}
*/
$past_permissions = apply_filters( 'wpt_past_tweets_capability', 'manage_options', $user_ID );
/**
* Filter the users allowed to see the XPoster Pro Failed Tweets screen.
*
* @hook wpt_error_tweets_capability
*
* @param {string} $allowed_group WordPress capability.
* @param {int} $user_ID Current user ID.
*
* @return {string}
*/
$error_permissions = apply_filters( 'wpt_error_tweets_capability', 'manage_options', $user_ID );
add_submenu_page( 'wp-tweets-pro', __( 'Pro Settings', 'wp-tweets-pro' ), __( 'Pro Settings', 'wp-tweets-pro' ), $allowed_group, 'wp-tweets-pro&tab=pro', $function );
add_submenu_page( 'wp-tweets-pro', __( 'Scheduled Tweets', 'wp-tweets-pro' ), __( 'Scheduled Tweets', 'wp-tweets-pro' ), $scheduled_permissions, 'wp-to-twitter-schedule', 'wpt_get_scheduled_tweets' );
$send = add_submenu_page( 'wp-tweets-pro', __( 'Sent Tweets', 'wp-tweets-pro' ), __( 'Sent Tweets', 'wp-tweets-pro' ), $past_permissions, 'wp-to-twitter-tweets', 'wpt_get_past_tweets' );
add_action( "load-$send", 'wpt_add_screen_option' );
$failed = add_submenu_page( 'wp-tweets-pro', __( 'Failed Tweets', 'wp-tweets-pro' ), __( 'Failed Tweets', 'wp-tweets-pro' ), $error_permissions, 'wp-to-twitter-errors', 'wpt_get_failed_tweets' );
add_action( "load-$failed", 'wpt_add_screen_option' );
}
}
/**
* Update Pro Settings
*/
function wpt_update_pro_settings() {
$message = '';
if ( isset( $_POST['wpt_license_key'] ) ) {
$wpt_license_key = sanitize_text_field( $_POST['wpt_license_key'] );
update_option( 'wpt_license_key', $wpt_license_key );
if ( '' !== (string) $wpt_license_key ) {
$confirmation = wpt_check_license( $wpt_license_key );
delete_option( 'wpt_license_status' );
} else {
$confirmation = 'deleted';
}
if ( WPT_DEBUG ) {
$notice = '<h3>License Activation Debugging</h3>';
$notice .= '<p><strong>' . 'Key sent:</strong> ' . $wpt_license_key . '</p>';
$notice .= '<pre>';
$debug = get_option( 'wpt_license_debug_trace' );
$notice .= print_r( $debug, 1 );
$notice .= '</pre>';
echo '<div class="notice notice-info">' . $notice . '</div>';
}
update_option( 'wpt_license_valid', $confirmation );
if ( 'inactive' === $confirmation ) {
$message = __( 'Your XPoster Pro key was not activated.', 'wp-tweets-pro' );
} elseif ( 'active' === $confirmation || 'valid' === $confirmation ) {
$message = __( 'Your XPoster Pro key has been activated! Enjoy!', 'wp-tweets-pro' );
} elseif ( 'deleted' === $confirmation ) {
$message = __( 'You have deleted your XPoster Pro license key.', 'wp-tweets-pro' );
} elseif ( 'invalid' === $confirmation ) {
if ( '' !== $wpt_license_key ) {
// Translators: Checkout link for renewal.
$message = sprintf( __( 'Your XPoster Pro license key is either expired or invalid. If expired, you can <a href="%s">renew now</a>.', 'wp-tweets-pro' ), esc_url( "https://www.xposterpro.com/checkout/?edd_license_key=$wpt_license_key&download_id=47131" ) );
} else {
// Translators: Account link.
$message = sprintf( __( 'Your XPoster Pro license key is either expired or invalid. <a href="%s">Log in to your account to check</a>.', 'wp-tweets-pro' ), 'https://www.xposterpro.com/account/' );
}
} else {
$message = __( 'XPoster 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 wp_kses_post( $notice );
}
if ( ! empty( $_POST['wp_pro_settings'] ) ) {
switch ( $_POST['wp_pro_settings'] ) {
case 'set':
$wpt_delay_tweets = (int) $_POST['wpt_delay_tweets'];
$wpt_retweet_after = (int) $_POST['wpt_retweet_after'];
if ( '' === trim( $wpt_delay_tweets ) ) {
$wpt_delay_tweets = 0;
}
if ( '' === trim( $wpt_retweet_after ) ) {
$wpt_retweet_after = 0;
}
$wpt_postpone_rendering = ( isset( $_POST['wpt_postpone_rendering'] ) ) ? 'true' : 'false';
update_option( 'wpt_postpone_rendering', $wpt_postpone_rendering );
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 = (int) $_POST['wpt_retweet_repeat'];
update_option( 'wpt_retweet_repeat', $wpt_retweet_repeat );
$wpt_custom_type = ( isset( $_POST['wpt_custom_type'] ) ) ? sanitize_text_field( $_POST['wpt_custom_type'] ) : 'prefix';
$wpt_prepend_rt3 = ( isset( $_POST['wpt_prepend_rt3'] ) ) ? sanitize_text_field( $_POST['wpt_prepend_rt3'] ) : '';
$wpt_prepend_rt2 = ( isset( $_POST['wpt_prepend_rt2'] ) ) ? sanitize_text_field( $_POST['wpt_prepend_rt2'] ) : '';
$wpt_prepend_rt = ( isset( $_POST['wpt_prepend_rt'] ) ) ? sanitize_text_field( $_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_og_card = ( isset( $_POST['wpt_og_card'] ) ) ? 1 : 0;
update_option( 'wpt_og_card', $wpt_og_card );
$wpt_twitter_card_type = ( isset( $_POST['wpt_twitter_card_type'] ) ) ? sanitize_text_field( $_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 );
$wpt_player_card_previous_status = get_option( 'wpt_player_card', '0' );
$wpt_player_card = ( isset( $_POST['wpt_player_card'] ) ) ? 1 : 0;
update_option( 'wpt_player_card', $wpt_player_card );
$player_card_enabled = '';
if ( 1 === $wpt_player_card && '0' === $wpt_player_card_previous_status ) {
// Translators: Twitter validation URL.
$player_card_enabled = sprintf( __( 'You just enabled Player Cards. Twitter Player Cards require a video and an image for each post with a Player Card. All assets must be loaded over SSL for the Player Card to work, and you <strong>must</strong> <a href="%s">validate a card successfully</a> before they will be shown on Twitter.', 'wp-tweets-pro' ), 'https://cards-dev.twitter.com/validator' );
}
if ( $player_card_enabled ) {
echo wp_kses_post( '<div class="notice updated"><p>' . $player_card_enabled . '</p></div>' );
}
$prepend = __( 'Warning: your status update re-posts are not differentiated. This may cause services to block your re-posted statuses.', 'wp-tweets-pro' );
$prepend_warning = '';
if ( 1 === (int) $wpt_retweet_repeat && '' === $wpt_prepend_rt ) {
$prepend_warning = $prepend;
}
if ( 2 === (int) $wpt_retweet_repeat && '' === $wpt_prepend_rt2 ) {
$prepend_warning = $prepend;
}
if ( 3 === (int) $wpt_retweet_repeat && '' === $wpt_prepend_rt3 ) {
$prepend_warning = $prepend;
}
$wpt_prepend = ( isset( $_POST['wpt_prepend'] ) && 'on' === $_POST['wpt_prepend'] ) ? 1 : 0;
update_option( 'wpt_prepend', $wpt_prepend );
$wpt_filter_title = ( isset( $_POST['wpt_filter_title'] ) && 'on' === $_POST['wpt_filter_title'] ) ? 1 : 0;
$wpt_filter_post = ( isset( $_POST['wpt_filter_post'] ) && 'on' === $_POST['wpt_filter_post'] ) ? 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'] ) && 'on' === $_POST['wpt_media'] ) ? 1 : 0;
update_option( 'wpt_media', $wpt_media );
update_option( 'jd_individual_twitter_users', ( isset( $_POST['jd_individual_twitter_users'] ) ? 1 : 0 ) );
$wpt_cotweet = ( isset( $_POST['wpt_cotweet'] ) && 'on' === $_POST['wpt_cotweet'] ) ? 1 : 0;
if ( 1 === $wpt_cotweet ) {
// If cotweeting is enabled, individual twitter users must also be enabled.
update_option( 'jd_individual_twitter_users', 1 );
}
update_option( 'wpt_cotweet', $wpt_cotweet );
$wpt_cotweet_lock = ( isset( $_POST['wpt_cotweet_lock'] ) && 'false' !== $_POST['wpt_cotweet_lock'] ) ? (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;
$start_time = ( isset( $_POST['wpt_start'] ) && '' !== $_POST['wpt_start'] ) ? strtotime( $_POST['wpt_start'] ) : false;
$is_scheduled = ( isset( $_POST['wpt_is_scheduled'] ) ) ? true : false;
if ( $schedule && ! $is_scheduled ) {
wpt_setup_schedules( $schedule, $start_time );
}
$schedule_template = ( isset( $_POST['wpt_schedule_template'] ) ) ? sanitize_textarea_field( $_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_only_custom = ( isset( $_POST['wpt_only_custom'] ) ) ? 'true' : 'false';
update_option( 'wpt_only_custom', $wpt_only_custom );
$wpt_autopost_notification = ( isset( $_POST['wpt_autopost_notification'] ) ) ? sanitize_text_field( $_POST['wpt_autopost_notification'] ) : false;
if ( $wpt_autopost_notification && is_email( $wpt_autopost_notification ) ) {
update_option( 'wpt_autopost_notification', $wpt_autopost_notification );
} else {
delete_option( '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'] ) ) ? map_deep( $_POST['wpt_autoretweet_post_types'], 'sanitize_text_field' ) : array();
update_option( 'wpt_autoretweet_post_types', $wpt_autoretweet_post_types );
// comment settings.
update_option( 'comment-published-text', ( isset( $_POST['comment-published-text'] ) ) ? sanitize_textarea_field( $_POST['comment-published-text'] ) : '' );
update_option( 'comment-published-update', ( isset( $_POST['comment-published-update'] ) ) ? sanitize_textarea_field( $_POST['comment-published-update'] ) : '' );
update_option( 'wpt_comment_delay', ( isset( $_POST['wpt_comment_delay'] ) ) ? (int) $_POST['wpt_comment_delay'] : '' );
$message = '<strong>' . __( 'XPoster 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;
}
}
}
/**
* XPoster Pro settings form
*/
function wpt_pro_functions() {
wpt_update_pro_settings();
wpt_build_filters();
echo '<div class="ui-sortable meta-box-sortables wp-tweets-pro">';
echo '<div class="postbox">';
$class = ( 'true' === get_option( 'wpt_license_valid' ) || 'valid' === get_option( 'wpt_license_valid' ) || 'active' === get_option( 'wpt_license_valid' ) ) ? 'valid' : 'invalid';
$active = ( 'valid' === $class ) ? ' <span class="activated">(' . __( 'activated', 'wp-tweets-pro' ) . ')</span>' : '';
$retweet = ( '' !== get_option( 'wpt_retweet_after' ) ) ? get_option( 'wpt_retweet_after' ) : '39.5';
$license_action = ( 'valid' === $class ) ? __( 'Update', 'wp-tweets-pro' ) : __( 'Activate', 'wp-tweets-pro' );
$button_type = ( 'valid' === $class ) ? 'button-secondary' : 'button-primary';
print(
'<h2><span>' . __( 'XPoster Pro Settings', 'wp-tweets-pro' ) . '</span></h2>
<div class="inside">' . wpt_license_data() . '
<form action="" method="post">
<p class="' . $class . '">
<label for="wpt_license_key">' . __( 'License Key', 'wp-tweets-pro' ) . $active . '</label><br/>
<input type="text" size="38" name="wpt_license_key" id="wpt_license_key" value="' . esc_attr( get_option( 'wpt_license_key' ) ) . '" /> <input type="submit" value="' . $license_action . '" class="' . $button_type . '" />
</p>
' . wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . '
</form>
</div>'
);
echo '</div>';
echo '</div>';
echo '<form action="" method="post">';
echo '<div class="ui-sortable meta-box-sortables wp-tweets-pro">';
echo '<div class="postbox">';
$wpt_twitter_card_type = get_option( 'wpt_twitter_card_type' );
echo '<h2>' . __( 'Image & Video Handling', 'wp-tweets-pro' ) . '</h2>';
echo '<div class="inside">';
echo '<p>You can use both uploaded images and Twitter Cards, but Twitter will only display one or the other. Uploaded images are associated with the Tweet using the image; Twitter Cards are associated with the link to the post you shared. Learn about <a href="https://dev.twitter.com/cards">Twitter Cards</a> →</p>';
print( '
<p>
<input type="checkbox" name="wpt_og_card" id="wpt_og_card" value="on" ' . checked( 1, get_option( 'wpt_og_card' ), false ) . '/>
<label for="wpt_og_card">' . __( 'Enable Mastodon Open Graph Cards', 'wp-tweets-pro' ) . '</label>
</p>
<p>
<input type="checkbox" name="wpt_twitter_card" id="wpt_twitter_card" value="on" ' . checked( 1, get_option( 'wpt_twitter_card' ), false ) . ' aria-describedby="tc_validation" />
<label for="wpt_twitter_card">' . __( 'Enable X.com Preview Cards', 'wp-tweets-pro' ) . '</label> <span id="tc_validation"><a href="https://cards-dev.twitter.com/validator">' . __( 'Validate Twitter Cards', 'wp-tweets-pro' ) . '</a></span>
</p>
<p>
<label for="wpt_twitter_card_type">' . __( 'Default Preview Card type', 'wp-tweets-pro' ) . '</label>
<select name="wpt_twitter_card_type" id="wpt_twitter_card_type" />
<option value="summary"' . selected( $wpt_twitter_card_type, 'summary', false ) . '>' . __( 'Summary', 'wp-tweets-pro' ) . '</option>
<option value="summary_large_image"' . selected( $wpt_twitter_card_type, 'summary_large_image', false ) . '>' . __( 'Summary, Large Image', 'wp-tweets-pro' ) . '</option>' );
if ( is_ssl() ) {
print( '<option value="player"' . selected( $wpt_twitter_card_type, 'player', false ) . '>' . __( 'Player', 'wp-tweets-pro' ) . '</option>' );
}
print( '</select>
</p>
<p>
<label for="wpt_toggle_card">' . __( 'Auto-enable photo card if post length less than', 'wp-tweets-pro' ) . '</label>
<input type="text" name="wpt_toggle_card" id="wpt_toggle_card" aria-labelledby="wpt_toggle_card wpt_tc_label" size="4" value="' . (int) get_option( 'wpt_toggle_card' ) . '" /> <span id="wpt_tc_label">' . __( 'characters', 'wp-tweets-pro' ) . '</span>
</p>' );
if ( is_ssl() ) {
echo '<p>
<input type="checkbox" name="wpt_player_card" id="wpt_player_card" value="on" ' . checked( 1, get_option( 'wpt_player_card' ), false ) . ' aria-describedby="tc_validation" />
<label for="wpt_player_card">' . __( 'Enable Player Cards.', 'wp-tweets-pro' ) . '</label> <span id="tc_validation"><a href="https://cards-dev.twitter.com/validator">' . __( 'Validate Twitter Cards', 'wp-tweets-pro' ) . '</a></span>
</p>';
} else {
echo '<p>' . __( 'Set up an SSL Certificat to enable Player cards for Twitter', 'wp-tweets-pro' ) . '</p>';
}
?>
</p>
<?php
if ( function_exists( 'curl_version' ) ) {
?>
<p>
<input type="checkbox" name="wpt_media" id="wpt_media" value="on" <?php checked( 1, get_option( 'wpt_media' ) ); ?> /> <label for="wpt_media"><?php _e( 'Upload images (Featured Image first, first other attached image otherwise.)', 'wp-tweets-pro' ); ?></label>
</p>
<?php
} else {
_e( '<em>Disabled</em>: cURL support not available.', 'wp-tweets-pro' );
}
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="ui-sortable meta-box-sortables wp-tweets-pro">';
echo '<div class="postbox">';
echo '<h2>' . __( 'Scheduling', 'wp-tweets-pro' ) . '</h2>';
echo '<div class="inside">';
$checked = ( 'true' === get_option( 'wpt_postpone_rendering', 'false' ) ) ? ' checked="checked"' : '';
print( '
<p>
<input type="checkbox" name="wpt_postpone_rendering" id="wpt_postpone_rendering" aria-describedy="postpone_rendering_desc" value="true"' . $checked . ' /> <label for="wpt_postpone_rendering">' . __( 'Render Templates when Tweeted', 'wp-tweets-pro' ) . '</label>
<br /><em id="postpone_rendering_desc">' . __( 'By default, Tweets are rendered when your post is published. For scheduled Tweets, this can be deferred until the Tweet is sent.', 'wp-tweets-pro' ) . '</em>
</p>
<p>
<label for="wpt_delay_tweets">' . __( 'Number of minutes to delay tweets', 'wp-tweets-pro' ) . '</label>
<input type="text" size="4" name="wpt_delay_tweets" id="wpt_delay_tweets" value="' . esc_attr( get_option( 'wpt_delay_tweets' ) ) . '" />
</p>
<p>
<label for="wpt_retweet_after">' . __( 'Re-post Tweet after how many hours', 'wp-tweets-pro' ) . '</label>
<input type="text" size="4" name="wpt_retweet_after" id="wpt_retweet_after" value="' . esc_attr( $retweet ) . '" />
</p>
<p>
<label for="wpt_retweet_repeat">' . __( 'Re-post Tweet how many times at this interval?', 'wp-tweets-pro' ) . '</label>
<select name="wpt_retweet_repeat" id="wpt_retweet_repeat">' );
/**
* Adjust the values available to choose for setting the number of times a Tweet can be reposted. Default `4`.
*
* @hook wpt_tweet_repeat_count
*
* @param {int} $count Maximum number of times a Tweet can be reposted.
*
* @return {int}
*/
$retweet_repeat_count = apply_filters( 'wpt_tweet_repeat_count', 4 );
for ( $i = 0; $i < $retweet_repeat_count; $i++ ) {
print( '<option value="' . $i . '"' . selected( get_option( 'wpt_retweet_repeat' ), $i, false ) . '>' . $i . ' </option>' );
}
print ( '
</select>
</p>
<p class="inline-labels">' . __( '<strong>Blackout Period</strong>: Reschedule Tweets if', 'wp-tweets-pro' ) . '
<label for="wpt_blackout_from">' . __( 'between', 'wp-tweets-pro' ) . '</label>
<select name="wpt_blackout_from" id="wpt_blackout_from">
<option value="0"> -- </option>
<optgroup label="' . __( 'AM', 'wp-tweets-pro' ) . '">' );
$wpt_blackout = ( is_array( get_option( 'wpt_blackout' ) ) ) ? get_option( 'wpt_blackout' ) : array(
'from' => 0,
'to' => 0,
);
for ( $i = 1; $i <= 24; $i++ ) {
print( '<option value="' . $i . '"' . selected( $wpt_blackout['from'], $i, false ) . '>' . $i . ':00 </option>' );
if ( 12 === $i ) {
print( '</optgroup><optgroup label="' . __( 'PM', 'wp-tweets-pro' ) . '">' );
}
}
print( '</optgroup></select>
<label for="wpt_blackout_to">' . __( 'and', 'wp-tweets-pro' ) . '</label>
<select name="wpt_blackout_to" id="wpt_blackout_to">
<option value="0"> -- </option>
<optgroup label="' . __( 'AM', 'wp-tweets-pro' ) . '">' );
for ( $i = 1; $i <= 24; $i++ ) {
print( '<option value="' . $i . '"' . selected( $wpt_blackout['to'], $i, false ) . '>' . $i . ':00 </option>' );
if ( 12 === $i ) {
print( '</optgroup><optgroup label="' . __( 'PM', 'wp-tweets-pro' ) . '">' );
}
}
print( '</optgroup></select>' );
if ( is_array( get_option( 'wpt_blackout' ) ) && ! ( $wpt_blackout['to'] === $wpt_blackout['from'] ) ) {
// Translators: Start hour, end hour.
print( '<br /><em>' . sprintf( __( 'Tweets rescheduled for times between %1$s:00 and %2$s:00.', 'wp-tweets-pro' ), $wpt_blackout['from'], $wpt_blackout['to'] ) . '</em>' );
}
$custom_type = get_option( 'wpt_custom_type' );
$prefix = ( 'prefix' === $custom_type || ! $custom_type ) ? ' checked="checked"' : '';
$template = ( 'template' === $custom_type ) ? ' checked="checked"' : '';
echo '</p>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="ui-sortable meta-box-sortables wp-tweets-pro">';
echo '<div class="postbox">';
echo '<h2>' . __( 'Differentiate Re-posted Tweets', 'wp-tweets-pro' ) . '</h2>';
echo '<div class="inside">';
print(
'<p>
<input type="radio" name="wpt_custom_type" id="wpt_custom_prefix" value="prefix"' . $prefix . ' /> <label for="wpt_custom_prefix">Custom Prefixes</label><br />
<input type="radio" name="wpt_custom_type" id="wpt_custom_template" value="template"' . $template . ' /> <label for="wpt_custom_template">Custom Templates</label>
<p>
<label for="wpt_prepend_rt">' . __( 'First Repost', 'wp-tweets-pro' ) . '</label>
<input type="text" size="32" name="wpt_prepend_rt" id="wpt_prepend_rt" value="' . esc_attr( stripslashes( get_option( 'wpt_prepend_rt' ) ) ) . '" /> <input type="checkbox" name="wpt_rt_media" id="wpt_rt_media" value="true" ' . checked( 'true', get_option( 'wpt_rt_media' ), false ) . ' /> <label for="wpt_rt_media">' . __( 'Exclude Media on First Repost', 'wp-tweets-pro' ) . '</label>
</p>
<p>
<label for="wpt_prepend_rt2">' . __( 'Second Repost', 'wp-tweets-pro' ) . '</label>
<input type="text" size="32" name="wpt_prepend_rt2" id="wpt_prepend_rt2" value="' . esc_attr( stripslashes( get_option( 'wpt_prepend_rt2' ) ) ) . '" /> <input type="checkbox" name="wpt_rt_media2" id="wpt_rt_media2" value="true" ' . checked( 'true', get_option( 'wpt_rt_media2' ), false ) . ' /> <label for="wpt_rt_media2">' . __( 'Exclude Media on Second Repost', 'wp-tweets-pro' ) . '</label>
</p>
<p>
<label for="wpt_prepend_rt3">' . __( 'Third Repost', 'wp-tweets-pro' ) . '</label>
<input type="text" size="32" name="wpt_prepend_rt3" id="wpt_prepend_rt3" value="' . esc_attr( stripslashes( get_option( 'wpt_prepend_rt3' ) ) ) . '" /> <input type="checkbox" name="wpt_rt_media3" id="wpt_rt_media3" value="true" ' . checked( 'true', get_option( 'wpt_rt_media3' ), false ) . ' /> <label for="wpt_rt_media3">' . __( 'Exclude Media on Third Repost', 'wp-tweets-pro' ) . '</label>
</p>'
);
if ( 'prefix' === $custom_type || ! $custom_type ) {
print( '
<p><input type="checkbox" name="wpt_prepend" id="wpt_prepend" value="on"' . checked( 1, get_option( 'wpt_prepend' ), false ) . ' />
<label for="wpt_prepend">' . __( 'Move repost prefixes to end of repost', 'wp-tweets-pro' ) . '</label>
</p>' );
}
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="ui-sortable meta-box-sortables wp-tweets-pro">';
echo '<div class="postbox">';
echo '<h2>' . __( 'Multi User Settings', 'wp-tweets-pro' ) . '</h2>';
echo '<div class="inside">';
print( '
<p>
<input type="checkbox" name="jd_individual_twitter_users" id="jd_individual_twitter_users" value="1"' . checked( '1', get_option( 'jd_individual_twitter_users' ), false ) . ' />
<label for="jd_individual_twitter_users">' . __( 'Enable User Account Settings', 'wp-tweets-pro' ) . '</label>
</p>
<p>
<input type="checkbox" name="wpt_cotweet" id="wpt_cotweet" value="on" ' . checked( 1, get_option( 'wpt_cotweet' ), false ) . ' />
<label for="wpt_cotweet">' . __( 'Send simultaneous updates to Main Site account and author\'s account.', 'wp-tweets-pro' ) . '</label>
</p>' );
$disabled = ( 1 !== (int) get_option( 'jd_individual_twitter_users' ) ) ? " disabled='disabled'" : '';
print( '
<p class="indent">
<label for="wpt_cotweet_lock">' . __( 'Send duplicate updates to:', 'wp-tweets-pro' ) . '</label>
<select name="wpt_cotweet_lock" id="wpt_cotweet_lock"' . $disabled . '>
<option value="false">' . __( 'Post author (default behavior)', 'wp-tweets-pro' ) . '</option>' );
$args = array(
'meta_query' => array(
array(
'key' => 'wtt_twitter_username',
'compare' => 'EXISTS',
),
),
);
// get all authorized users.
$users = get_users( $args );
$authorized_users = array();
foreach ( $users as $this_user ) {
if ( wtt_oauth_test( $this_user->ID, 'verify' ) ) {
$twitter = get_user_meta( $this_user->ID, 'wtt_twitter_username', true );
$authorized_users[] = array(
'ID' => $this_user->ID,
'name' => $this_user->display_name,
'twitter' => $twitter,
);
print( '<option value="' . absint( $this_user->ID ) . '" ' . selected( $this_user->ID, get_option( 'wpt_cotweet_lock' ), false ) . '>' . esc_html( $this_user->display_name ) . ' (@' . esc_html( $twitter ) . ')</option>' );
}
}
update_option( 'wpt_authorized_users', $authorized_users );
print( '</select></p>' );
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="ui-sortable meta-box-sortables wp-tweets-pro">';
echo '<div class="postbox">';
echo '<h2>' . __( 'Add hashtag filters', 'wp-tweets-pro' ) . '</h2>';
echo '<div class="inside">';
print( '<p>
<input type="checkbox" name="wpt_filter_title" id="wpt_filter_title" value="on" ' . checked( 1, get_option( 'wpt_filter_title' ), false ) . ' />
<label for="wpt_filter_title">' . __( 'Filter Post Titles and insert hashtags', 'wp-tweets-pro' ) . '</label>
</p>
<p>
<input type="checkbox" name="wpt_filter_post" id="wpt_filter_post" value="on"' . checked( 1, get_option( 'wpt_filter_post' ), false ) . ' />
<label for="wpt_filter_post">' . __( 'Filter Post excerpts and insert hashtags', 'wp-tweets-pro' ) . '</label>
</p>' );
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="ui-sortable meta-box-sortables wp-tweets-pro">';
echo '<div class="postbox">';
echo '<h2>' . __( 'Tweet Comments', 'wp-tweets-pro' ) . '</h2>';
echo '<div class="inside">';
if ( 1 === (int) get_option( 'comment_moderation' ) || 1 === (int) get_option( 'comment_previously_approved' ) ) {
?>
<p>
<input type="checkbox" name="comment-published-update" id="comment-published-update" value="1" <?php checked( 1, get_option( 'comment-published-update' ) ); ?> />
<label for="comment-published-update"><strong><?php _e( 'Update when new comments are posted', 'wp-tweets-pro' ); ?></strong></label><br />
<label for="comment-published-text"><?php _e( 'Template for new comments:', 'wp-tweets-pro' ); ?></label> <textarea aria-labelledby="comment-published-text-label" type="text" class="wpt-template" name="comment-published-text" id="comment-published-text" class="widefat" maxlength="120"><?php echo ( esc_textarea( stripslashes( get_option( 'comment-published-text' ) ) ) ); ?></textarea>
</p>
<p>
<label for="wpt_comment_delay"><?php _e( 'Delay comment Tweets (minutes)', 'wp-tweets-pro' ); ?></label> <input type="number" name="wpt_comment_delay" id="wpt_comment_delay" value="<?php echo esc_attr( get_option( 'wpt_comment_delay' ) ); ?>" />
</p>
<p id='comment-published-text-label'>
<?php
_e( 'Comment templates can use <code>#commenter#</code> for the commenter\'s name, <code>#comment#</code> for an excerpt of the comment, <code>#comment_url#</code> to link to the comment, and <code>#comment_date#</code>. Comments will be Tweeted immediately when approved, or automatically if commenter has the "moderate comments" capability.', 'wp-tweets-pro' );
} else {
$url = admin_url( 'options-discussion.php#moderation_notify' );
// Translators: Url to enable admin moderation of comments.
printf( __( "<em>Disabled</em>: Require <a href='%s'>administrator moderation of comments</a> or a previously approved comment to enable Tweeting comments.", 'wp-tweets-pro' ), $url );
}
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="ui-sortable meta-box-sortables wp-tweets-pro">';
echo '<div class="postbox">';
echo '<h2>' . __( 'Custom Tweet Filters', 'wp-tweets-pro' ) . '</h2>';
echo '<div class="inside">';
print( '<p>' . __( 'Use these filters to set custom rules to block tweeting.', 'wp-tweets-pro' ) . '</p>' . wpt_setup_filters() );
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="ui-sortable meta-box-sortables wp-tweets-pro">';
echo '<div class="postbox">';
echo '<h2>' . __( 'Automatically Tweet Old Posts', 'wp-tweets-pro' ) . '</h2>';
echo '<div class="inside">';
echo '<p>' . __( 'Set up a regular schedule to auto-select and publish Tweets from your old posts.', 'wp-tweets-pro' ) . '</p>';
if ( '' !== get_option( 'wpt_schedule', '' ) ) {
?>
<p class="wpt-has-schedule">
<input type='hidden' name='wpt_is_scheduled' value='on' />
<input type='checkbox' id='wpt_unschedule' name='wpt_unschedule' value="true" /> <label for='wpt_unschedule'>
<?php
_e( 'Cancel scheduled posting cycle', 'wp-tweets-pro' );
echo ' (' . get_option( 'wpt_schedule' ) . ')';
?>
</p>
<?php
}
?>
<p>
<label for='wpt_schedule'><?php _e( 'Autopost interval', 'wp-tweets-pro' ); ?></label>
<select name='wpt_schedule' id='wpt_schedule'>
<option value=''><?php _e( 'None selected', 'wp-tweets-pro' ); ?></option>
<?php
// note: if a schedule is set, show checkbox to delete existing schedule and create new.
$schedules = wp_get_schedules();
foreach ( $schedules as $key => $schedule ) {
echo "<option value='" . esc_attr( $key ) . "'" . selected( get_option( 'wpt_schedule' ), $key ) . '>' . esc_html( $schedule['display'] ) . '</option>';
}
?>
</select>
</p>
<p>
<label for='wpt_start'><?php _e( 'Autopost start time', 'wp-tweets-pro' ); ?></label>
<input type='time' name='wpt_start' id='wpt_start' value='' />
</p>
<p>
<label for='wpt_schedule_template'><?php _e( 'Template for autoscheduled posts', 'wp-tweets-pro' ); ?></label>
<textarea name='wpt_schedule_template' id='wpt_schedule_template' cols='60' rows='3' class='wpt-template' placeholder="#title# #url#"><?php echo esc_textarea( stripslashes( get_option( 'wpt_schedule_template' ) ) ); ?></textarea>
</p>
<p>
<input type="checkbox" id="wpt_schedule_custom" name="wpt_schedule_custom" value="true"<?php checked( get_option( 'wpt_schedule_custom' ), 'true' ); ?> /> <label for="wpt_schedule_custom"><?php _e( 'Use custom Tweet template when available', 'wp-tweets-pro' ); ?></label>
</p>
<p>
<input type="checkbox" name="wpt_only_custom" id="wpt_only_custom" value="true"<?php checked( get_option( 'wpt_only_custom' ), 'true' ); ?> /> <label for="wpt_only_custom"><?php _e( 'Only Tweet posts with existing custom Tweet text', 'wp-tweets-pro' ); ?></label>
</p>
<p>
<label for="wpt_minimum_age"><?php _e( 'Minimum age eligible for automatic Tweeting', 'wp-tweets-pro' ); ?></label>
<select name='wpt_minimum_age' id='wpt_minimum_age'>
<option value='none'<?php selected( get_option( 'wpt_minimum_age' ), 1 ); ?>><?php _e( 'No limit', 'wp-tweets-pro' ); ?></option>
<option value='2592000'<?php selected( get_option( 'wpt_minimum_age' ), 2592000 ); ?>><?php _e( '1 month', 'wp-tweets-pro' ); ?></option>
<option value='7776000'<?php selected( get_option( 'wpt_minimum_age' ), 7776000 ); ?>><?php _e( '3 months', 'wp-tweets-pro' ); ?></option>
<option value='15552000'<?php selected( get_option( 'wpt_minimum_age' ), 15552000 ); ?>><?php _e( '6 months', 'wp-tweets-pro' ); ?></option>
<option value='31536000'<?php selected( get_option( 'wpt_minimum_age' ), 31536000 ); ?>><?php _e( '12 months', 'wp-tweets-pro' ); ?></option>
</select>
</p>
<p>
<label for="wpt_maximum_age"><?php _e( 'Maximum age eligible for automatic Tweeting', 'wp-tweets-pro' ); ?></label>
<select name='wpt_maximum_age' id='wpt_maximum_age'>
<option value='none'<?php selected( get_option( 'wpt_maximum_age' ), 1 ); ?>><?php _e( 'No limit', 'wp-tweets-pro' ); ?></option>
<option value='2628000'<?php selected( get_option( 'wpt_maximum_age' ), 2628000 ); ?>><?php _e( '1 month', 'wp-tweets-pro' ); ?></option>
<option value='7884000'<?php selected( get_option( 'wpt_maximum_age' ), 7884000 ); ?>><?php _e( '3 months', 'wp-tweets-pro' ); ?></option>
<option value='15768000'<?php selected( get_option( 'wpt_maximum_age' ), 15768000 ); ?>><?php _e( '6 months', 'wp-tweets-pro' ); ?></option>
<option value='31536000'<?php selected( get_option( 'wpt_maximum_age' ), 31536000 ); ?>><?php _e( '12 months', 'wp-tweets-pro' ); ?></option>
<option value='63072000'<?php selected( get_option( 'wpt_maximum_age' ), 63072000 ); ?>><?php _e( '2 years', 'wp-tweets-pro' ); ?></option>
<option value='157680000'<?php selected( get_option( 'wpt_maximum_age' ), 157680000 ); ?>><?php _e( '5 years', 'wp-tweets-pro' ); ?></option>
<option value='315360000'<?php selected( get_option( 'wpt_maximum_age' ), 315360000 ); ?>><?php _e( '10 years', 'wp-tweets-pro' ); ?></option>
</select>
</p>
<fieldset>
<legend><?php _e( 'Automatically Tweet these post types', 'wp-tweets-pro' ); ?></legend>
<ul class='checkboxes'>
<?php
$post_types = get_post_types( array( 'public' => true ), 'objects' );
$wpt_post_types = get_option( 'wpt_autoretweet_post_types' );
if ( ! is_array( $wpt_post_types ) ) {
$wpt_post_types = array();
}
$wpt_post_type_options = '';
foreach ( $post_types as $type ) {
if ( 'mc-events' === $type->name ) {
continue;
}
if ( in_array( $type->name, $wpt_post_types, true ) ) {
$selected = ' checked="checked"';
} else {
$selected = '';
}
$wpt_post_type_options .= "<li><input type='checkbox' id='" . sanitize_title( $type->name ) . "' name='wpt_autoretweet_post_types[]' value='$type->name'$selected> <label for='" . sanitize_title( $type->name ) . "'>" . $type->labels->name . '</label></li>';
}
echo $wpt_post_type_options;
?>
</ul>
</fieldset>
<p>
<label for='wpt_autopost_notification'><?php _e( 'Email me about autoposted Tweets', 'wp-tweets-pro' ); ?></label>
<input type='email' name='wpt_autopost_notification' id='wpt_autopost_notification' value='<?php echo esc_attr( get_option( 'wpt_autopost_notification' ) ); ?>' placeholder="<?php esc_attr_e( 'Email address', 'wp-tweets-pro' ); ?>" />
</p>
<?php
echo '
<p class="submit">
<input type="submit" name="submit" class="button-primary" value="' . __( 'Update XPoster Pro Settings', 'wp-tweets-pro' ) . '" />
</p>
<input type="hidden" name="wp_pro_settings" value="set" class="hidden" />
' . wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . '
</div>';
echo '</div></form>
</div>';
}
/**
* Activate license.
*
* @param string $license_key License key to activate.
* @param string $request Type of action to perform.
*
* @return string|bool License key status.
*/
function wpt_check_license( $license_key, $request = 'activate' ) {
// listen for our activate button to be clicked.
if ( isset( $_POST['wpt_license_key'] ) ) {
// run a quick security check.
if ( ! check_admin_referer( 'wp-to-twitter-nonce', '_wpnonce' ) ) {
return; // get out if we didn't click the Activate button.
}
// data to send in our API request.
$action = ( 'activate' === $request ) ? 'activate_license' : 'check_license';
$api_params = array(
'edd_action' => $action,
'license' => $license_key,
'item_id' => EDD_WPT_ITEM_ID, // the ID of our product in EDD.
'url' => home_url(),
);
// Call the custom API.
$response = wp_remote_post(
EDD_WPT_STORE_URL,
array(
'timeout' => 15,
'body' => $api_params,
)
);
// make sure the response came back okay.
if ( is_wp_error( $response ) ) {
if ( WPT_DEBUG ) {
update_option( 'wpt_license_debug_trace', $response );
}
return false;
}
// decode the license data.
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
if ( WPT_DEBUG ) {
update_option( 'wpt_license_debug_trace', $license_data );
}
// $license_data->license will be either "active" or "inactive".
if ( is_object( $license_data ) ) {
return $license_data->license;
} else {
return false;
}
}
}
/**
* Recheck a license to see current state.
*
* @param string $key License key.
* @param boolean $force Force a recheck.
*/
function wpt_recheck_license( $key, $force = false ) {
if ( '' === $key ) {
return;
}
$transient = get_transient( 'wpt_last_check' );
if ( $transient && ! $force ) {
return;
} else {
$api_params = array(
'edd_action' => 'check_license',
'license' => $key,
'item_id' => EDD_WPT_ITEM_ID, // the name of our product in EDD.
'url' => home_url(),
);
// Call the custom API.
$response = wp_remote_post(
EDD_WPT_STORE_URL,
array(
'timeout' => 15,
'body' => $api_params,
)
);
// make sure the response came back okay.
if ( is_wp_error( $response ) ) {
return false;
}
// decode the license data.
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
update_option(
'wpt_license_status',
array( current_time( 'timestamp' ) => $license_data ) // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
);
set_transient( 'wpt_last_check', true, DAY_IN_SECONDS );
}
}
/**
* Get current license data.
*
* @return HTML.
*/
function wpt_license_data() {
$wpt_license_key = get_option( 'wpt_license_key' );
if ( '' === $wpt_license_key ) {
return "<div class='wpt-license-status none'><p>" . __( 'Please enter your license key', 'wp-tweets-pro' ) . '</p></div>';
}
wpt_recheck_license( $wpt_license_key );
$wpt_license = get_option( 'wpt_license_status' );
$output = '';
$state = 'none';
if ( ! empty( $wpt_license ) ) {
foreach ( $wpt_license as $test => $status ) {
$date = date_i18n( 'Y-m-d', $test );
if ( is_object( $status ) ) {
if ( ! $wpt_license_key ) {
update_option( 'wpt_license_status', '' );
continue;
}
if ( 'invalid' === $status->license ) {
$state = 'invalid';
// Translators: License key.
$output = '<p>' . sprintf( __( '%s is not a valid license key. Please re-check your entry and try again!', 'wp-tweets-pro' ), '<code>' . esc_html( $wpt_license_key ) . '</code>' ) . '</p>';
} else {
$expires = ( 'lifetime' === $status->expires ) ? 'Lifetime' : date_i18n( 'Y-m-d', strtotime( $status->expires ) );
if ( 'lifetime' !== $status->expires && strtotime( $status->expires ) < $test ) {
$state = 'expired';
// Translators: link to renew license.
$output = '<p>' . sprintf( __( 'Your license has expired. <a href="%s">Renew your license now!</a>', 'wp-tweets-pro' ), esc_url( "https://www.xposterpro.com/checkout/?edd_license_key=$wpt_license_key&download_id=5729" ) ) . '</p>';
} else {
$state = 'active';
$license = $wpt_license_key;
$email = $status->customer_email;
if ( 'Lifetime' === $expires ) {
// Translators: type of license, customer's email.
$license_check = sprintf( __( 'You have a %1$s license. Thank you! Your customer email is %2$s.', 'wp-tweets-pro' ), "<strong>$expires</strong>", "<strong>$email</strong>" );
} else {
// Translators: Date license will expire. License key. Customer email.
$license_check = sprintf( __( 'License expires on %1$s. License is %2$s. Your customer email is %3$s.', 'wp-tweets-pro' ), "<strong>$expires</strong>", "<strong>$license</strong>", "<strong>$email</strong>" );
}
// Translators: Date license last checked.
$output = wp_kses_post( '<p>' . sprintf( __( 'Last Checked: %s', 'wp-tweets-pro' ), "<strong>$date</strong>" ) . "</p><p class='wpt-check-license'>" . $license_check . '</p>' );
}
}
} else {
// if not a valid object, don't return anything.
$output = '';
}
}
}
return ( '' === $output ) ? '' : "<div class='wpt-license-status $state'>" . $output . '</div>';
}
if ( '1' === get_option( 'jd_individual_twitter_users' ) ) {
add_filter( 'manage_users_columns', 'wpt_add_column' );
/**
* Add user management columns if users are enabled.
*
* @param array $columns Existing columns.
*/
function wpt_add_column( $columns ) {
$columns['wpt_twitter'] = 'Twitter';
return $columns;
}
add_action( 'manage_users_custom_column', 'wpt_column_content', 10, 3 );
/**
* Get custom column content for XPoster columns.
*
* @param mixed $value Current value.
* @param string $column_name Internal name of column.
* @param int $user_id Object ID.
*
* @return new value.
*/
function wpt_column_content( $value, $column_name, $user_id ) {
$user = get_userdata( $user_id );
if ( 'wpt_twitter' === $column_name ) {
$twitter = get_user_meta( $user_id, 'wtt_twitter_username', true );
if ( $twitter && wtt_oauth_test( $user_id, 'verify' ) ) {
$twitter = '<span class="authorized">@' . esc_html( $twitter ) . '</span>';
return $twitter;
}
if ( $twitter ) {
return '@' . $twitter;
}
if ( '' !== get_user_meta( $user_id, 'wp-to-twitter-user-username', true ) ) {
$account = '@' . esc_html( get_user_meta( $user_id, 'wp-to-twitter-user-username', true ) );
return $account;
}
return __( 'None', 'wp-tweets-pro' );
}
return $value;
}
}
add_filter( 'wpt_save_user', 'wpt_update_user_oauth', 10, 2 );
/**
* Save user settings & connect user to Twitter
*
* @param int $edit_id User ID.
* @param array $post POST data.
*
* @return User ID.
*/
function wpt_update_user_oauth( $edit_id, $post ) {
if ( current_user_can( 'wpt_twitter_oauth' ) || current_user_can( 'manage_options' ) ) {
if ( function_exists( 'wpt_pro_exists' ) && ( ! empty( $_POST['wtt_app_consumer_key'] ) || isset( $_POST['oauth_settings'] ) ) ) {
$message = wpt_update_oauth_settings( $edit_id, $post );
switch ( $message ) {
case 'success':
$message = __( 'You have successfully connected your profile to Twitter', 'wp-tweets-pro' );
break;
case 'failed':
$message = __( 'We could not connect your profile to Twitter. Please check your application keys and settings and try again.', 'wp-tweets-pro' );
break;
case 'nodata':
$message = '';
break;
case 'nosync':
$message = __( 'We could not connect your profile to Twitter due to a time discrepancy between this server and Twitter.', 'wp-tweets-pro' );
break;
case 'cleared':
$message = __( 'You have successfully disconnected your profile from Twitter', 'wp-tweets-pro' );
break;
default:
break;
}
update_user_meta( $edit_id, 'wpt-connection-message', $message );
} else {
delete_user_meta( $edit_id, 'wpt-connection-message' );
}
}
return $edit_id;
}
add_filter( 'wpt_save_user', 'wpt_update_twitter_user_fields', 10, 2 );
/**
* Save user settings
*
* @param int $edit_id User ID.
* @param array $post POST data.
*
* @return User ID.
*/
function wpt_update_twitter_user_fields( $edit_id, $post ) {
if ( current_user_can( 'wpt_twitter_oauth' ) || current_user_can( 'manage_options' ) ) {
if ( function_exists( 'wpt_pro_exists' ) ) {
if ( isset( $post['submit'] ) ) {
$templates = isset( $post['wpt_templates'] ) ? map_deep( $post['wpt_templates'], 'sanitize_textarea_field' ) : '';
update_user_meta( $edit_id, 'wpt_templates', $templates );
$reposts = isset( $post['wpt_retweet_repeat'] ) ? absint( $post['wpt_retweet_repeat'] ) : '';
update_user_meta( $edit_id, 'wpt_retweet_repeat', $reposts );
}
}
}
return $edit_id;
}