diff --git a/src/wp-to-twitter.php b/src/wp-to-twitter.php index 27685ee..7deb4ad 100644 --- a/src/wp-to-twitter.php +++ b/src/wp-to-twitter.php @@ -320,7 +320,7 @@ function wpt_check_recent_tweet( $id, $auth ) { * @param int $id Post ID. * @param boolean $media Whether to upload media attached to the post specified in $id. * - * @return boolean Success of query. + * @return boolean|array False if blocked, array of statuses if attempted. */ function wpt_post_to_service( $text, $auth = false, $id = false, $media = false ) { $return = wpt_post_to_twitter( $text, $auth, $id, $media ); @@ -336,10 +336,11 @@ function wpt_post_to_service( $text, $auth = false, $id = false, $media = false * @param int $id Post ID. * @param boolean $media Whether to upload media attached to the post specified in $id. * - * @return boolean Success of query. + * @return boolean|array False if blocked, array of statuses if attempted. */ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false ) { // If an ID is set but the post is not currently present or published, ignore. + $return = array(); if ( $id ) { $status = get_post_status( $id ); if ( ! $status || 'publish' !== $status ) { @@ -422,17 +423,19 @@ function wpt_post_to_twitter( $twit, $auth = false, $id = false, $media = false $status = wpt_upload_twitter_media( $connection, $auth, $attachment, $status, $id ); $response = wpt_send_post_to_twitter( $connection, $auth, $id, $status ); wpt_post_submit_handler( $connection, $response, $id, $auth, $twit ); + $return['xcom'] = $response; } if ( wpt_mastodon_connection( $auth ) ) { $connection = wpt_mastodon_connection( $auth ); $status = wpt_upload_mastodon_media( $connection, $auth, $attachment, $status, $id ); $response = wpt_send_post_to_mastodon( $connection, $auth, $id, $status ); wpt_post_submit_handler( $connection, $response, $id, $auth, $twit ); + $return['mastodon'] = $response; } wpt_mail( 'X Connection', "$twit, $auth, $id, $media", $id ); - if ( $connection ) { + if ( ! empty( $return ) ) { - return $response['return']; + return $return; } else { wpt_set_log( 'wpt_status_message', $id, __( 'No API connection found.', 'wp-to-twitter' ) ); @@ -501,7 +504,7 @@ function wpt_post_submit_handler( $connection, $response, $id, $auth, $twit ) { 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' ) ); + wpt_set_log( 'wpt_status_message', $id, $notice . ' ' . __( 'Status sent successfully.', 'wp-to-twitter' ) ); } } diff --git a/src/wpt-functions.php b/src/wpt-functions.php index 7159dd8..ee281ca 100644 --- a/src/wpt-functions.php +++ b/src/wpt-functions.php @@ -123,11 +123,18 @@ function wpt_check_functions() { if ( wtt_oauth_test() || wpt_mastodon_connection() ) { $rand = wp_rand( 1000000, 9999999 ); $testpost = wpt_post_to_service( "This is a test of XPoster. $shrink ($rand)" ); - if ( $testpost ) { - $message .= '
  • ' . __( 'XPoster successfully submitted a status update to X.com.', 'wp-to-twitter' ) . '
  • '; + if ( $testpost && ! empty( $testpost ) ) { + foreach ( $testpost as $key => $test ) { + if ( 'xcom' === $key ) { + $message .= '
  • ' . __( 'XPoster successfully submitted a status update to X.com.', 'wp-to-twitter' ) . '
  • '; + } + if ( 'mastodon' === $key ) { + $message .= '
  • ' . __( 'XPoster successfully submitted a status update to your Mastodon instance.', 'wp-to-twitter' ) . '
  • '; + } + } } else { $error = wpt_get_log( 'wpt_status_message', 'test' ); - $message .= '
  • ' . __( 'XPoster failed to submit an update to X.com.', 'wp-to-twitter' ) . '
  • '; + $message .= '
  • ' . __( 'XPoster failed to submit status updates.', 'wp-to-twitter' ) . '
  • '; $message .= "
  • $error
  • "; } } else { diff --git a/src/wpt-post-to-mastodon.php b/src/wpt-post-to-mastodon.php index 60e9ca8..8543f6f 100644 --- a/src/wpt-post-to-mastodon.php +++ b/src/wpt-post-to-mastodon.php @@ -73,6 +73,7 @@ function wpt_upload_mastodon_media( $connection, $auth, $attachment, $status, $i * @return array */ function wpt_send_post_to_mastodon( $connection, $auth, $id, $status ) { + $notice = ''; /** * Turn on staging mode. Staging mode is automatically turned on if WPT_STAGING_MODE constant is defined. * @@ -126,13 +127,14 @@ function wpt_send_post_to_mastodon( $connection, $auth, $id, $status ) { $success = true; $http_code = 200; $status_id = $return['id']; + $notice .= __( 'Successful status update sent to Mastodon.', 'wp-to-twitter' ); } else { $http_code = 401; - $notice = __( 'Status update failed.', 'wp-to-twitter' ); + $notice .= __( 'Mastodon status update failed.', 'wp-to-twitter' ); } } else { $http_code = '000'; - $notice = __( 'Status Update cancelled by custom filter.', 'wp-to-twitter' ); + $notice .= __( 'Mastodon status update cancelled by custom filter.', 'wp-to-twitter' ); } }