From 32bdb6ccffebaca084bb6efc08c54e7b8f2a8b39 Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Sat, 30 Dec 2023 16:23:28 -0600 Subject: [PATCH] Add return handlers for mastodon settings --- readme.md | 2 +- src/wp-to-twitter-manager.php | 43 ++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 9283d81..caa02d1 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # XPoster -Automatically send your posts as Tweets. +Automatically send your posts as X.com or Mastodon status updates. ![Code Linting](https://github.com/joedolson/wp-to-twitter/actions/workflows/main.yml/badge.svg) [![License](https://img.shields.io/badge/license-GPL--2.0%2B-green.svg)](https://www.gnu.org/license/gpl-2.0.html) diff --git a/src/wp-to-twitter-manager.php b/src/wp-to-twitter-manager.php index 9ffde46..33291c2 100644 --- a/src/wp-to-twitter-manager.php +++ b/src/wp-to-twitter-manager.php @@ -37,9 +37,9 @@ function wpt_updated_settings() { // Connect to Mastodon. if ( isset( $_POST['mastodon_settings'] ) ) { $post = map_deep( $_POST, 'sanitize_text_field' ); - $oauth_message = wpt_update_mastodon_settings( false, $post ); + $mastodon_message = wpt_update_mastodon_settings( false, $post ); } else { - $oauth_message = ''; + $mastodon_message = ''; } $message = ''; @@ -50,7 +50,7 @@ function wpt_updated_settings() { print( '
-

' . __( 'XPoster is now connected with X.com.', 'wp-to-twitter' ) . " " . __( 'Configure your Tweet templates', 'wp-to-twitter' ) . '

+

' . __( 'XPoster is now connected with X.com.', 'wp-to-twitter' ) . " " . __( 'Configure your status update templates', 'wp-to-twitter' ) . '

' ); } elseif ( 'failed' === $oauth_message ) { @@ -86,6 +86,43 @@ function wpt_updated_settings() { } } + // notifications from Mastodon connection. + if ( isset( $_POST['mastodon_settings'] ) ) { + if ( 'success' === $mastodon_message ) { + $admin_url = admin_url( 'admin.php?page=wp-tweets-pro?tab=basic' ); + + print( ' +
+

' . __( 'XPoster is now connected to your Mastodon instance.', 'wp-to-twitter' ) . " " . __( 'Configure your status update templates', 'wp-to-twitter' ) . '

+
+ ' ); + } elseif ( 'failed' === $mastodon_message ) { + print( ' +
+

' . __( 'XPoster failed to connect with your Mastodon instance.', 'wp-to-twitter' ) . ' ' . __( 'Error:', 'wp-to-twitter' ) . ' ' . get_option( 'wpt_error' ) . '

+
+ ' ); + } elseif ( 'cleared' === $mastodon_message ) { + print( ' +
+

' . __( 'Mastodon authentication data cleared.', 'wp-to-twitter' ) . '

+
+ ' ); + } elseif ( 'noconnection' === $oauth_message ) { + print( ' +
+

' . __( 'Mastodon authentication Failed. XPoster was unable to complete a connection with those credentials.', 'wp-to-twitter' ) . '

+
+ ' ); + } else { + print( ' +
+

' . __( 'Mastodon authentication response not understood.', 'wp-to-twitter' ) . '

+
+ ' ); + } + } + if ( isset( $_POST['submit-type'] ) && 'advanced' === $_POST['submit-type'] ) { $default = ( isset( $_POST['jd_tweet_default'] ) ) ? sanitize_textarea_field( $_POST['jd_tweet_default'] ) : 0; $default_edit = ( isset( $_POST['jd_tweet_default_edit'] ) ) ? sanitize_textarea_field( $_POST['jd_tweet_default_edit'] ) : 0;