Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
younes-dro committed Jan 15, 2023
1 parent 82e5c4e commit 3d25e2e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
22 changes: 21 additions & 1 deletion admin/class-connect-profilepress-and-discord-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ public function ets_ppress_discord_setting_page() {
require_once ETS_PROFILEPRESS_DISCORD_PLUGIN_DIR_PATH . 'admin/partials/connect-profilepress-and-discord-admin-display.php';
}

/**
* Callback to Connect to bot
*
* @since 1.0.0
*/
public function ets_profilepress_discord_connect_to_bot() {

if ( current_user_can( 'administrator' ) && isset( $_GET['action'] ) && $_GET['action'] == 'profilepress-discord-connect-to-bot' ) {
$params = array(
'client_id' => sanitize_text_field( trim( get_option( 'ets_profilepress_discord_client_id' ) ) ),
'permissions' => ETS_PROFILEPRESS_DISCORD_BOT_PERMISSIONS,
'scope' => 'bot',
'guild_id' => sanitize_text_field( trim( get_option( 'ets_profilepress_discord_server_id' ) ) ),
);
$discord_authorise_api_url = ETS_PROFILEPRESS_DISCORD_API_URL . 'oauth2/authorize?' . http_build_query( $params );

wp_redirect( $discord_authorise_api_url, 302, get_site_url() );
exit;
}
}
/**
* Save application details
*
Expand Down Expand Up @@ -595,7 +615,7 @@ public function ets_profilepress_discord_send_support_mail() {
*/
public function ets_ppress_subscription_status_updated( $subscription_status, $old_status, $subscription ) {

//update_option( 'subscription_status_' . time(), $subscription_status );
// update_option( 'subscription_status_' . time(), $subscription_status );

$user_id = ets_profilepress_discord_get_user_id( $subscription->customer_id );
if ( $subscription_status === 'completed' ) {
Expand Down
1 change: 1 addition & 0 deletions admin/css/connect-profilepress-and-discord-admin.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions admin/js/connect-profilepress-and-discord-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
success: function (response) {
if (response != null && response.hasOwnProperty('code') && response.code == 50001 && response.message == 'Missing Access') {
$(".profilepress-btn-connect-to-bot").show();
} else if ( response.code === 10004 && response.message == 'Unknown Guild' ) {
$(".profilepress-btn-connect-to-bot").show().after('<p><b>The server ID is wrong or you did not connect the Bot.</b></p>');
}else if( response.code === 0 && response.message == '401: Unauthorized' ) {
$(".profilepress-btn-connect-to-bot").show().html("Error: Unauthorized - The Bot Token is wrong").addClass('error-bk');
} else if (response == null || response.message == '401: Unauthorized' || response.hasOwnProperty('code') || response == 0) {
$("#profilepress-connect-discord-bot").show().html("Error: Please check all details are correct").addClass('error-bk');
} else {
Expand Down
Loading

0 comments on commit 3d25e2e

Please sign in to comment.