Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display invalid private token notice #141

Merged
merged 6 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions includes/class-import-eventbrite-events-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public function iee_check_for_minimum_pro_version() {
* @param array $eventbrite_event Eventbrite event.
* @return array
*/
public function display_import_success_message( $import_data = array(), $import_args = array(), $schedule_post = '' ) {
public function display_import_success_message( $import_data = array(), $import_args = array(), $schedule_post = '', $error_reason = '' ) {
global $iee_success_msg, $iee_errors;
if ( ! empty( $iee_errors ) ) {
return;
Expand Down Expand Up @@ -491,7 +491,10 @@ public function display_import_success_message( $import_data = array(), $import_
if ( $skip_trash > 0 ) {
$success_message .= "<strong>" . sprintf( __( '%d Skipped (Already exists in Trash )', 'import-eventbrite-events' ), $skip_trash ) . "</strong><br>";
}
$iee_success_msg[] = $success_message;
if ( !empty( $error_reason ) ) {
$success_message .= "<strong>" . sprintf( __( '%d ', 'import-eventbrite-events' ), $error_reason ) . "</strong><br>";
}
$iee_success_msg[] = $success_message;

if ( $schedule_post != '' && $schedule_post > 0 ) {
$temp_title = get_the_title( $schedule_post );
Expand All @@ -518,6 +521,7 @@ public function display_import_success_message( $import_data = array(), $import_
update_post_meta( $insert, 'skipped', $skipped );
update_post_meta( $insert, 'skip_trash', $skip_trash );
update_post_meta( $insert, 'nothing_to_import', $nothing_to_import );
update_post_meta( $insert, 'error_reason', $error_reason );
update_post_meta( $insert, 'imported_data', $import_data );
update_post_meta( $insert, 'import_data', $import_args );
if ( $schedule_post != '' && $schedule_post > 0 ) {
Expand Down
25 changes: 23 additions & 2 deletions includes/class-import-eventbrite-events-eventbrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public function import_event_by_event_id( $event_data = array() ) {
return $this->save_eventbrite_event( $eventbrite_event, $event_data );

} else {
if( $eventbrite_event['error'] == 'INVALID_AUTH' ){
$error_description = str_replace( 'OAuth token', 'Private token', $eventbrite_event['error_description'] );
$iee_errors[] = __( $error_description, 'import-eventbrite-events-pro');
return;
}
$iee_errors[] = __( 'Something went wrong, please try again.', 'import-eventbrite-events' );
return;
}
Expand Down Expand Up @@ -191,7 +196,15 @@ public function get_organizer( $eventbrite_event ) {
return null;
}
$event_organizer = $eventbrite_event['organizer_id'];
$get_oraganizer = wp_remote_get( 'https://www.eventbriteapi.com/v3/organizers/' . $event_organizer . '/?token=' . $this->oauth_token, array( 'headers' => array( 'Content-Type' => 'application/json' ) ) );
$get_oraganizer = wp_remote_get(
'https://www.eventbriteapi.com/v3/organizers/' . $event_organizer . '/?token=' . $this->oauth_token,
array(
'headers' => array(
'Content-Type' => 'application/json'
),
'timeout' => 20,
)
);

if ( ! is_wp_error( $get_oraganizer ) ) {
$oraganizer = json_decode( $get_oraganizer['body'], true );
Expand Down Expand Up @@ -280,7 +293,15 @@ public function get_organizer_name_by_id( $organizer_id ) {
return;
}

$get_oraganizer = wp_remote_get( 'https://www.eventbriteapi.com/v3/organizers/' . $organizer_id . '/?token=' . $this->oauth_token, array( 'headers' => array( 'Content-Type' => 'application/json' ) ) );
$get_oraganizer = wp_remote_get(
'https://www.eventbriteapi.com/v3/organizers/' . $organizer_id . '/?token=' . $this->oauth_token,
array(
'headers' => array(
'Content-Type' => 'application/json'
),
'timeout' => 20,
)
);

if ( ! is_wp_error( $get_oraganizer ) ) {
$oraganizer = json_decode( $get_oraganizer['body'], true );
Expand Down
20 changes: 15 additions & 5 deletions includes/class-import-eventbrite-events-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,16 @@ function get_scheduled_import_data( $origin = '' ) {
if( !empty( $stats ) ){
$stats = esc_html__( 'Last Import Stats: ', 'import-eventbrite-events' ).'<span style="color: silver">'.implode(', ', $stats).'</span>';
}else{
$error_reason = get_post_meta( $history[0], 'error_reason', true );
$nothing_to_import = get_post_meta( $history[0], 'nothing_to_import', true );
if( $nothing_to_import ){
$stats = '<span style="color: silver">'.__( 'No events are imported.', 'import-eventbrite-events' ).'</span>';
if( !empty( $error_reason ) ){
$stats = __( '<span style="color: red"><strong>The Private token you provided was invalid.</strong></span>', 'import-eventbrite-events' ) . '<br>';
}else{
$stats = '';
if( $nothing_to_import ){
$stats = '<span style="color: silver">'.__( 'No events are imported.', 'import-eventbrite-events' ).'</span>';
}else{
$stats = '';
}
}
}
}
Expand Down Expand Up @@ -462,6 +467,7 @@ function column_stats( $item ) {
$updated = get_post_meta( $item['ID'], 'updated', true );
$skipped = get_post_meta( $item['ID'], 'skipped', true );
$skip_trash = get_post_meta( $item['ID'], 'skip_trash', true );
$error_reason = get_post_meta( $item['ID'], 'error_reason', true );
$nothing_to_import = get_post_meta( $item['ID'], 'nothing_to_import', true );

$success_message = '<span style="color: silver"><strong>';
Expand All @@ -477,8 +483,12 @@ function column_stats( $item ) {
if ( $skip_trash > 0 ) {
$success_message .= sprintf( __( '%d Skipped in Trash', 'import-eventbrite-events' ), $skip_trash ) . '<br>';
}
if( $nothing_to_import ){
$success_message .= __( 'No events are imported.', 'import-eventbrite-events' ) . '<br>';
if( !empty( $error_reason ) ){
$success_message .= __( 'The Private token you provided was invalid.', 'import-eventbrite-events' ) . '<br>';
}else{
if( $nothing_to_import ){
$success_message .= __( 'No events are imported.', 'import-eventbrite-events' ) . '<br>';
}
}
$success_message .= '</strong></span>';

Expand Down
Loading