diff --git a/src/wp-to-twitter-manager.php b/src/wp-to-twitter-manager.php index 9bbe5d4..9ffde46 100644 --- a/src/wp-to-twitter-manager.php +++ b/src/wp-to-twitter-manager.php @@ -631,11 +631,11 @@ function wpt_update_settings() { global $wp_roles; $roles = $wp_roles->get_names(); $caps = array( - 'wpt_can_tweet' => __( 'Can send Tweets', 'wp-to-twitter' ), - 'wpt_twitter_custom' => __( 'See Custom Tweet Field when creating a Post', 'wp-to-twitter' ), - 'wpt_twitter_switch' => __( 'Toggle the Tweet/Don\'t Tweet option', 'wp-to-twitter' ), - 'wpt_tweet_now' => __( 'Can see Tweet Now button', 'wp-to-twitter' ), - 'wpt_twitter_oauth' => __( 'Allow user to authenticate with X.com', 'wp-to-twitter' ), + 'wpt_can_tweet' => __( 'Can send Status updates', 'wp-to-twitter' ), + 'wpt_twitter_custom' => __( 'See Custom Status Update Field when creating a Post', 'wp-to-twitter' ), + 'wpt_twitter_switch' => __( 'Toggle the Update/Don\'t Update option', 'wp-to-twitter' ), + 'wpt_tweet_now' => __( 'Can see Update Now button', 'wp-to-twitter' ), + 'wpt_twitter_oauth' => __( 'Allow user to authenticate with services', 'wp-to-twitter' ), ); $role_tabs = ''; $role_container = ''; diff --git a/src/wp-to-twitter.php b/src/wp-to-twitter.php index 86a685a..039e928 100644 --- a/src/wp-to-twitter.php +++ b/src/wp-to-twitter.php @@ -8,9 +8,9 @@ * @license GPL-2.0+ * * @wordpress-plugin - * Plugin Name: XPoster - Share to Twitter/X from WordPress + * Plugin Name: XPoster - Share to X.com and Mastodon from WordPress * Plugin URI: http://www.joedolson.com/wp-to-twitter/ - * Description: Posts a Tweet when you update your WordPress blog or post a link, using your URL shortener. Many options to customize and promote your Tweets. + * Description: Posts a status update when you update your WordPress blog or post a link, using your URL shortener. Many options to customize and promote your statuses. * Author: Joseph C Dolson * Author URI: http://www.joedolson.com * Text Domain: wp-to-twitter @@ -194,7 +194,7 @@ function wptotwitter_activate() { } /** - * Function checks for an alternate URL to be Tweeted. Contribution by Bill Berry. + * Function checks for an alternate URL to be updated. Contribution by Bill Berry. * * @param int $post_ID Post ID. * @@ -212,13 +212,13 @@ function wpt_link( $post_ID ) { } /** - * Save error messages for Tweets. + * Save error messages for status updates. * * @param int $id Post ID. * @param int $auth Current author. - * @param string $twit Tweet text. - * @param string $error Error string from X.com. - * @param int $http_code Http code from X.com. + * @param string $twit Update text. + * @param string $error Error string from service. + * @param int $http_code Http code from service. * @param string $ts Current timestamp. */ function wpt_save_error( $id, $auth, $twit, $error, $http_code, $ts ) { @@ -243,10 +243,10 @@ function wpt_save_error( $id, $auth, $twit, $error, $http_code, $ts ) { } /** - * Save a record of a successful Tweet. + * Save a record of a successful status update. * * @param int $id Post ID. - * @param string $twit Tweet text. + * @param string $twit Status update text. * @param int $http_code HTTP Code returned by query. */ function wpt_save_success( $id, $twit, $http_code ) { @@ -272,7 +272,7 @@ function wpt_save_success( $id, $twit, $http_code ) { * @param int $auth Author. * * @uses filter wpt_recent_tweet_threshold - * @return boolean true to send Tweet, false to block. + * @return boolean true to send status update, false to block. */ function wpt_check_recent_tweet( $id, $auth ) { if ( ! $id ) { @@ -287,7 +287,8 @@ function wpt_check_recent_tweet( $id, $auth ) { return true; } else { /** - * Modify the expiration window for recent Tweets. This value does flood control, to prevent a runaway process from sending multiple Tweets. Default `30` seconds. + * Modify the expiration window for recent status updates. + * This value does flood control, to prevent a runaway process from sending multiple status updates. Default `30` seconds. * * @hook wpt_recent_tweet_threshold * @param {int} $expire Integer representing seconds. How long the transient will exist. @@ -297,7 +298,7 @@ function wpt_check_recent_tweet( $id, $auth ) { $expire = apply_filters( 'wpt_recent_tweet_threshold', 30 ); // if expiration is 0, don't set the transient. We don't want permanent transients. if ( 0 !== $expire ) { - wpt_mail( 'Tweet transient set', "$expire / $auth / $id", $id ); + wpt_mail( 'Update transient set', "$expire / $auth / $id", $id ); if ( false === $auth ) { set_transient( "_wpt_most_recent_tweet_$id", true, $expire ); } else { @@ -362,7 +363,7 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false $recent = wpt_check_recent_tweet( $id, $auth ); if ( $recent ) { - wpt_mail( 'This post was just Tweeted, and this is a duplicate.', 'Post ID: ' . $id . '; Account: ' . $auth ); + wpt_mail( 'This post was just sent, and this is a duplicate.', 'Post ID: ' . $id . '; Account: ' . $auth ); return false; } @@ -384,10 +385,10 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false } // exit silently if not authorized. $check = ( ! $auth ) ? get_option( 'jd_last_tweet', '' ) : get_user_meta( $auth, 'wpt_last_tweet', true ); // get user's last tweet. - // prevent duplicate Tweets. Checks whether this text has already been sent. + // prevent duplicate status updates. Checks whether this text has already been sent. if ( $check === $twit && '' !== $twit ) { wpt_mail( 'Matched: status update identical', "This Update: $twit; Check Update: $check; $auth, $id, $media", $id ); // DEBUG. - $error = __( 'This status update is identical to another update recently sent to this account.', 'wp-to-twitter' ) . ' ' . __( 'X.com requires all Tweets to be unique.', 'wp-to-twitter' ); + $error = __( 'This status update is identical to another update recently sent to this account.', 'wp-to-twitter' ) . ' ' . __( 'All status updates are expected to be unique.', 'wp-to-twitter' ); wpt_save_error( $id, $auth, $twit, $error, '403-1', time() ); wpt_set_log( 'wpt_status_message', $id, $error ); @@ -454,9 +455,10 @@ function wpt_post_submit_handler( $connection, $response, $id, $auth, $twit ) { $return = $response['return']; $http_code = $response['http']; $notice = $response['notice']; - $tweet_id = $response['tweet_id']; + $tweet_id = isset( $response['tweet_id'] ) ? $response['tweet_id'] : false; + $status_id = isset( $response['status_id'] ) ? $response['status_id'] : false; wpt_mail( "X.com Response: $http_code", $error, $id ); // DEBUG. - // only save last Tweet if successful. + // only save last status if successful. if ( 200 === $http_code ) { if ( ! $auth ) { update_option( 'jd_last_tweet', $twit ); @@ -468,33 +470,38 @@ function wpt_post_submit_handler( $connection, $response, $id, $auth, $twit ) { wpt_save_success( $id, $twit, $http_code ); if ( ! $return ) { /** - * Executes an action after posting a Tweet fails. + * Executes an action after posting a status fails. * * @hook wpt_tweet_failed * * @since 3.6.0 * * @param {object} $connection The current OAuth connection. - * @param {int} $id Post ID for Tweeted post. + * @param {int} $id Post ID for status update. * @param {string} $error Error message returned. */ do_action( 'wpt_tweet_failed', $connection, $id, $error ); wpt_set_log( 'wpt_status_message', $id, $error ); } else { /** - * Executes an action after a Tweet is posted successfully. + * Executes an action after a status is posted successfully. * * @hook wpt_tweet_posted * * @param {object} $connection The current OAuth connection. - * @param {int} $id Post ID for Tweeted post. + * @param {int} $id Post ID for status update. */ do_action( 'wpt_tweet_posted', $connection, $id ); - // Log the Tweet ID of the first Tweet for this post. + // Log the Status ID of the first Tweet on this post. $has_tweet_id = get_post_meta( $id, '_wpt_tweet_id', true ); if ( ! $has_tweet_id && $tweet_id ) { update_post_meta( $id, '_wpt_tweet_id', $tweet_id ); } + // Log the Status ID of the first non-Tweet update on this post. + $has_status_id = get_post_meta( $id, '_wpt_status_id', true ); + if ( ! $has_status_id && $status_id ) { + update_post_meta( $id, '_wpt_status_id', $status_id ); + } wpt_set_log( 'wpt_status_message', $id, $notice . __( 'Status sent successfully.', 'wp-to-twitter' ) ); } } @@ -707,11 +714,11 @@ function wpt_is_ssl( $url ) { } /** - * Builds array of post info for use in Tweet functions. + * Builds array of post info for use in status update functions. * * @param integer $post_ID Post ID. * - * @return array Post data used in Tweet functions. + * @return array Post data used in status update functions. */ function wpt_post_info( $post_ID ) { $encoding = get_option( 'blog_charset', '' ); @@ -755,7 +762,7 @@ function wpt_post_info( $post_ID ) { * Filter the space separated list of category names in #cats#. * * @hook wpt_twitter_category_names - * @param {array} $cats Array of category names attached to this Tweet. + * @param {array} $cats Array of category names attached to this status update. * * @return {array} */ @@ -764,7 +771,7 @@ function wpt_post_info( $post_ID ) { * Filter the space separated list of category descriptions in #cat_descs#. * * @hook wpt_twitter_category_descs - * @param {array} $cats Array of category descriptions attached to this Tweet. + * @param {array} $cats Array of category descriptions attached to this status update. * * @return {array} */ @@ -798,7 +805,7 @@ function wpt_post_info( $post_ID ) { $values['postStatus'] = $post->post_status; $values['postType'] = $post->post_type; /** - * Filters post array to insert custom data that can be used in Tweet process. + * Filters post array to insert custom data that can be used in status update process. * * @param array $values Existing values. * @param integer $post_ID Post ID. @@ -884,7 +891,7 @@ function wpt_category_limit( $post_type, $post_info, $post_ID ) { } /** - * Set up a Tweet to be sent. + * Set up a status update to be sent. * * @param int $post_ID Post ID. * @param string $type Publishing context: instant, future, xmlrpc. @@ -922,7 +929,7 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null, $default = ( 'yes' === $tweet_this ) ? true : false; $text_default = 'yes'; } - wpt_mail( '1: Tweet Status', "Should tweet: $tweet_this; Setting: $text_default; Publication method: $type", $post_ID ); // DEBUG. + wpt_mail( '1: Status Update', "Should send: $tweet_this; Setting: $text_default; Publication method: $type", $post_ID ); // DEBUG. if ( $default ) { // default switch: depend on default settings. $post_info = wpt_post_info( $post_ID ); $media = wpt_post_with_media( $post_ID, $post_info ); @@ -947,7 +954,7 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null, * Return true to ignore this post based on POST data. Default false. * * @hook wpt_filter_post_data - * @param {bool} $filter True if this post should not be Tweeted. + * @param {bool} $filter True if this post should not have a status update sent. * @param {array} $post POST global. * * @return {bool} @@ -981,7 +988,7 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null, wpt_mail( '4b: XPoster Pro: Limited by term filters', 'This post was rejected by a taxonomy/term filter', $post_ID ); return false; } - // create Tweet and ID whether current action is edit or new. + // create status update and ID whether current action is edit or new. $ct = get_post_meta( $post_ID, '_jd_twitter', true ); if ( isset( $_POST['_jd_twitter'] ) && '' !== trim( $_POST['_jd_twitter'] ) ) { $ct = sanitize_textarea_field( $_POST['_jd_twitter'] ); @@ -1011,7 +1018,7 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null, if ( $newpost || $oldpost ) { $template = ( '' !== $custom_tweet ) ? $custom_tweet : $nptext; $sentence = jd_truncate_tweet( $template, $post_info, $post_ID ); - wpt_mail( '5: Tweet Template Processed', "Template: $template; Tweet: $sentence", $post_ID ); // DEBUG. + wpt_mail( '5: Status Update Template Processed', "Template: $template; Status: $sentence", $post_ID ); // DEBUG. if ( function_exists( 'wpt_pro_exists' ) && true === wpt_pro_exists() ) { $sentence2 = jd_truncate_tweet( $template, $post_info, $post_ID, false, $auth ); } @@ -1044,7 +1051,7 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null, $time = apply_filters( 'wpt_schedule_delay', ( (int) $post_info['wpt_delay_tweet'] ) * 60, $acct ); /** - * Render the template of a scheduled Tweet only at the time it's sent. + * Render the template of a scheduled status update only at the time it's sent. * * @hook wpt_postpone_rendering * @param {bool} $postpone True to postpone rendering. @@ -1068,7 +1075,7 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null, if ( WPT_DEBUG ) { $author_id = ( $acct ) ? "#$acct" : 'Main'; wpt_mail( - "7a: Tweet Scheduled for author: $author_id", + "7a: Status update Scheduled for author: $author_id", print_r( array( 'id' => $acct, @@ -1101,7 +1108,7 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null, $retweet = apply_filters( 'wpt_set_retweet_text', $template, $i, $post_ID ); /** - * Render the template of a scheduled Tweet only at the time it's sent. + * Render the template of a scheduled status only at the time it's sent. * * @hook wpt_postpone_rendering * @param {bool} $postpone True to postpone rendering. @@ -1120,7 +1127,7 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null, } // add original delay to schedule. $delay = ( isset( $post_info['wpt_delay_tweet'] ) ) ? ( (int) $post_info['wpt_delay_tweet'] ) * 60 : 0; - // Don't delay the first Tweet of the group. + // Don't delay the first stats update of the group. $offset = ( true === $first ) ? 0 : wp_rand( 60, 240 ); // delay each co-tweet by 1-4 minutes. $time = apply_filters( 'wpt_schedule_retweet', ( $post_info['wpt_retweet_after'] ) * ( 60 * 60 ) * $i, $acct, $i, $post_info ); wp_schedule_single_event( @@ -1177,7 +1184,7 @@ function wpt_tweet( $post_ID, $type = 'instant', $post = null, $updated = null, } /** - * Send Tweets on links in link manager. Only active if Link plug-in is installed. + * Send updates on links in link manager. Only active if Link plug-in is installed. * * @param integer $link_id Database ID for link. * @@ -1226,7 +1233,7 @@ function wpt_twit_link( $link_id ) { * * @param int $post_ID Post ID. * - * @return string $hashtags Hashtags in format needed for Tweet. + * @return string $hashtags Hashtags in format needed for status updates. */ function wpt_generate_hash_tags( $post_ID ) { $hashtags = ''; @@ -1393,7 +1400,7 @@ function wpt_add_twitter_inner_box( $post ) { // don't display when draft is updated or if no message. if ( ! ( ( '1' === $_REQUEST['message'] ) && ( 'publish' === $status && '1' !== $options[ $type ]['post-edited-update'] ) ) && 'no' !== $tweet_this ) { $log = wpt_get_log( 'wpt_status_message', $post_id ); - $class = ( __( 'Tweet sent successfully.', 'wp-to-twitter' ) !== $log ) ? 'error' : 'updated'; + $class = ( __( 'Status update sent successfully.', 'wp-to-twitter' ) !== $log ) ? 'error' : 'updated'; if ( '' !== trim( $log ) ) { echo "
$log