Skip to content

Commit

Permalink
Make notices about connecting to services dismissible as long as a se…
Browse files Browse the repository at this point in the history
…rvice is connected
  • Loading branch information
joedolson committed Jan 18, 2024
1 parent 1ae075b commit 2d17f55
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ label[for="wpt_license_key"] {
vertical-align: inherit;
}

#wp-to-twitter .xposter-connection.dismissible {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
}

#wpt_settings_page .tabs {
margin: .5em 0 0;
padding: 0 4px;
Expand Down
9 changes: 0 additions & 9 deletions src/wp-to-twitter-mastodon.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ function wtt_connect_mastodon( $auth = false ) {
echo '<div class="postbox">';
}
$information = '';

if ( $auth ) {
wpt_update_authenticated_users();
}
Expand All @@ -116,14 +115,6 @@ function wtt_connect_mastodon( $auth = false ) {
$nonce = ( ! $auth ) ? wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . wp_referer_field( false ) . '</form>' : '';
$connect = wpt_mastodon_connection( $auth );
if ( ! $connect ) {
// show notification to authenticate with OAuth. No longer global; settings only.
if ( ! wpt_check_oauth() && ! ( isset( $_GET['tab'] ) && 'connection' === $_GET['tab'] ) ) {
$admin_url = admin_url( 'admin.php?page=wp-tweets-pro&tab=mastodon' );
// Translators: Settings page to authenticate via OAuth.
$message = sprintf( __( "Mastodon requires authentication. <a href='%s'>Update your settings</a> to enable XPoster to send updates to Mastodon.", 'wp-to-twitter' ), $admin_url );
echo "<div class='error'><p>$message</p></div>";
}

$ack = ( ! $auth ) ? get_option( 'wpt_mastodon_token' ) : get_user_meta( $auth, 'wpt_mastodon_token', true );
$acs = ( ! $auth ) ? get_option( 'wpt_mastodon_instance' ) : get_user_meta( $auth, 'wpt_mastodon_instance', true );

Expand Down
8 changes: 0 additions & 8 deletions src/wp-to-twitter-oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,6 @@ function wtt_connect_oauth( $auth = false ) {
<input type="text" size="45" name="wtt_bearer_token" id="wtt_bearer_token" value="%s" />
</p>';
if ( ! wtt_oauth_test( $auth, 'verify' ) ) {
// show notification to authenticate with OAuth. No longer global; settings only.
if ( ! wpt_check_oauth() && ! ( isset( $_GET['tab'] ) && 'connection' === $_GET['tab'] ) ) {
$admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
// Translators: Settings page to authenticate via OAuth.
$message = sprintf( __( "X.com requires authentication by OAuth. You will need to <a href='%s'>update your settings</a> to complete installation of XPoster.", 'wp-to-twitter' ), $admin_url );
echo "<div class='error'><p>$message</p></div>";
}

$ack = ( ! $auth ) ? get_option( 'app_consumer_key' ) : get_user_meta( $auth, 'app_consumer_key', true );
$acs = ( ! $auth ) ? get_option( 'app_consumer_secret' ) : get_user_meta( $auth, 'app_consumer_secret', true );
$ot = ( ! $auth ) ? get_option( 'oauth_token' ) : get_user_meta( $auth, 'oauth_token', true );
Expand Down
40 changes: 40 additions & 0 deletions src/wp-to-twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2145,3 +2145,43 @@ function wpt_needs_bearer_token() {
}
}
}

function wpt_dismiss_connection() {
if ( isset( $_GET['page'] ) && 'wp-tweets-pro' === $_GET['page'] && isset( $_GET['dismiss'] ) && 'connection' === $_GET['dismiss'] ) {
update_option( 'wpt_ignore_connection', 'true' );
}
}
add_action( 'admin_init', 'wpt_dismiss_connection' );
/**
* Display notices if update services are not connected.
*/
function wpt_needs_connection() {
if ( isset( $_GET['page'] ) && 'wp-tweets-pro' === $_GET['page'] && ! 'true' === get_option( 'wpt_ignore_connection' ) ) {
$message = '';
$mastodon = wpt_mastodon_connection();
$x = wpt_check_oauth();
// show notification to authenticate with OAuth. No longer global; settings only.
if ( ! $mastodon && ! ( isset( $_GET['tab'] ) && 'connection' === $_GET['tab'] ) ) {
$admin_url = admin_url( 'admin.php?page=wp-tweets-pro&tab=mastodon' );
// Translators: Settings page to authenticate Mastodon.
$message = '<p>' . sprintf( __( "Mastodon requires authentication. <a href='%s'>Update your settings</a> to enable XPoster to send updates to Mastodon.", 'wp-to-twitter' ), $admin_url ) . '</p>';
}
// show notification to authenticate with OAuth. No longer global; settings only.
if ( ! $x && ! ( isset( $_GET['tab'] ) && 'connection' === $_GET['tab'] ) ) {
$admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
// Translators: Settings page to authenticate X.com.
$message = '<p>' . sprintf( __( "X.com requires authentication by OAuth. <a href='%s'>Update your settings</a> to enable XPoster to send updates to X.com.", 'wp-to-twitter' ), $admin_url ) . '</p>';
}
$is_dismissible = '';
$class = 'xposter-connection';
if ( $x || $mastodon ) {
$class = 'xposter-connection dismissible';
$dismiss_url = add_query_arg( 'dismiss', 'connection', admin_url( 'admin.php?page=wp-tweets-pro' ) );
$is_dismissible = ' <a href="' . esc_url( $dismiss_url ) . '" class="button button-secondary">' . __( 'Ignore', 'wp-to-twitter' ) . '</a>';;
}
if ( $message ) {
echo "<div class='notice notice-error $class'>$message $is_dismissible</div>";
}
}
}
add_action( 'admin_notices', 'wpt_needs_connection' );

0 comments on commit 2d17f55

Please sign in to comment.