Skip to content

Commit

Permalink
Add return handlers for mastodon settings
Browse files Browse the repository at this point in the history
  • Loading branch information
joedolson committed Dec 30, 2023
1 parent bb4f9ab commit 32bdb6c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
43 changes: 40 additions & 3 deletions src/wp-to-twitter-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';

Expand All @@ -50,7 +50,7 @@ function wpt_updated_settings() {

print( '
<div id="message" class="updated fade">
<p>' . __( 'XPoster is now connected with X.com.', 'wp-to-twitter' ) . " <a href='$admin_url'>" . __( 'Configure your Tweet templates', 'wp-to-twitter' ) . '</a></p>
<p>' . __( 'XPoster is now connected with X.com.', 'wp-to-twitter' ) . " <a href='$admin_url'>" . __( 'Configure your status update templates', 'wp-to-twitter' ) . '</a></p>
</div>
' );
} elseif ( 'failed' === $oauth_message ) {
Expand Down Expand Up @@ -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( '
<div id="message" class="updated fade">
<p>' . __( 'XPoster is now connected to your Mastodon instance.', 'wp-to-twitter' ) . " <a href='$admin_url'>" . __( 'Configure your status update templates', 'wp-to-twitter' ) . '</a></p>
</div>
' );
} elseif ( 'failed' === $mastodon_message ) {
print( '
<div id="message" class="error fade">
<p>' . __( 'XPoster failed to connect with your Mastodon instance.', 'wp-to-twitter' ) . ' <strong>' . __( 'Error:', 'wp-to-twitter' ) . '</strong> ' . get_option( 'wpt_error' ) . '</p>
</div>
' );
} elseif ( 'cleared' === $mastodon_message ) {
print( '
<div id="message" class="updated fade">
<p>' . __( 'Mastodon authentication data cleared.', 'wp-to-twitter' ) . '</p>
</div>
' );
} elseif ( 'noconnection' === $oauth_message ) {
print( '
<div id="message" class="error fade">
<p>' . __( 'Mastodon authentication Failed. XPoster was unable to complete a connection with those credentials.', 'wp-to-twitter' ) . '</p>
</div>
' );
} else {
print( '
<div id="message" class="error fade">
<p>' . __( 'Mastodon authentication response not understood.', 'wp-to-twitter' ) . '</p>
</div>
' );
}
}

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;
Expand Down

0 comments on commit 32bdb6c

Please sign in to comment.