Skip to content

Commit a497523

Browse files
authored
Merge pull request #167 from xylusthemes/private_token_warning
display invalid private token notice
2 parents c090c30 + d3c445c commit a497523

File tree

4 files changed

+84
-50
lines changed

4 files changed

+84
-50
lines changed

includes/class-wp-event-aggregator-common.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public function wpea_get_ticket_section( $eventbrite_id = 0 ) {
508508
* @param array $eventbrite_event Eventbrite event.
509509
* @return array
510510
*/
511-
public function display_import_success_message( $import_data = array(),$import_args = array(), $schedule_post = '' ) {
511+
public function display_import_success_message( $import_data = array(),$import_args = array(), $schedule_post = '', $error_reason = '' ) {
512512
global $wpea_success_msg, $wpea_errors;
513513
if ( ! empty( $wpea_errors ) ) {
514514
return;
@@ -552,6 +552,11 @@ public function display_import_success_message( $import_data = array(),$import_a
552552
if( $skip_trash > 0 ){
553553
$success_message .= "<strong>".sprintf( __( '%d Skipped (Already exists in Trash)', 'wp-event-aggregator' ), $skip_trash ) ."</strong><br>";
554554
}
555+
556+
if ( !empty( $error_reason ) ) {
557+
$success_message .= "<strong>" . sprintf( __( '%d ', 'wp-event-aggregator' ), $error_reason ) . "</strong><br>";
558+
}
559+
555560
$wpea_success_msg[] = $success_message;
556561

557562
if( $schedule_post != '' && $schedule_post > 0 ){
@@ -581,6 +586,7 @@ public function display_import_success_message( $import_data = array(),$import_a
581586
update_post_meta( $insert, 'nothing_to_import', $nothing_to_import );
582587
update_post_meta( $insert, 'imported_data', $import_data );
583588
update_post_meta( $insert, 'import_data', $import_args );
589+
update_post_meta( $insert, 'error_reason', $error_reason );
584590
if( $schedule_post != '' && $schedule_post > 0 ){
585591
update_post_meta( $insert, 'schedule_import_id', $schedule_post );
586592
}

includes/class-wp-event-aggregator-eventbrite.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public function import_events( $event_data = array() ){
9494
return $imported_events;
9595

9696
}else{
97+
if( $eventbrite_events['error'] == 'INVALID_AUTH' ){
98+
$error_description = str_replace( 'OAuth token', 'Private token', $eventbrite_events['error_description'] );
99+
$wpea_errors[] = __( $error_description, 'wp-event-aggregator');
100+
return;
101+
}
97102
$wpea_errors[] = __( 'Something went wrong, please try again.', 'wp-event-aggregator');
98103
return;
99104
}
@@ -144,6 +149,12 @@ public function import_event_by_event_id( $event_data = array() ){
144149
$imported_events[] = $this->save_eventbrite_event( $eventbrite_event, $event_data );
145150

146151
}else{
152+
153+
if( $eventbrite_event['error'] == 'INVALID_AUTH' ){
154+
$error_description = str_replace( 'OAuth token', 'Private token', $eventbrite_event['error_description'] );
155+
$wpea_errors[] = __( $error_description, 'wp-event-aggregator');
156+
return;
157+
}
147158
$wpea_errors[] = sprintf( esc_html__( 'Something went wrong with Eventbrite event ID: %s, please try again.', 'wp-event-aggregator' ), $eventbrite_id ) ;
148159
continue;
149160
}
@@ -254,7 +265,7 @@ public function get_organizer( $eventbrite_event ) {
254265
return null;
255266
}
256267
$event_organizer = $eventbrite_event['organizer_id'];
257-
$get_oraganizer = wp_remote_get( 'https://www.eventbriteapi.com/v3/organizers/' . $event_organizer .'/?token=' . $this->oauth_token, array( 'headers' => array( 'Content-Type' => 'application/json' ) ) );
268+
$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, ) );
258269

259270
if ( ! is_wp_error( $get_oraganizer ) ) {
260271
$oraganizer = json_decode( $get_oraganizer['body'], true );
@@ -351,7 +362,7 @@ public function get_organizer_name_by_id( $organizer_id ) {
351362
return;
352363
}
353364

354-
$get_oraganizer = wp_remote_get( 'https://www.eventbriteapi.com/v3/organizers/' . $organizer_id .'/?token=' . $this->oauth_token, array( 'headers' => array( 'Content-Type' => 'application/json' ) ) );
365+
$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, ) );
355366

356367
if ( ! is_wp_error( $get_oraganizer ) ) {
357368
$oraganizer = json_decode( $get_oraganizer['body'], true );

includes/class-wp-event-aggregator-list-table.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,16 @@ function get_scheduled_import_data( $origin = '' ) {
356356
if( !empty( $stats ) ){
357357
$stats = esc_html__( 'Last Import Stats: ', 'wp-event-aggregator' ).'<span style="color: silver">'.implode(', ', $stats).'</span>';
358358
}else{
359+
$error_reason = get_post_meta( $history[0], 'error_reason', true );
359360
$nothing_to_import = get_post_meta( $history[0], 'nothing_to_import', true );
360-
if( $nothing_to_import ){
361-
$stats = '<span style="color: silver">'.__( 'No events are imported.', 'wp-event-aggregator' ).'</span>';
361+
if( !empty( $error_reason ) ){
362+
$stats = __( '<span style="color: red"><strong>The Private token you provided was invalid.</strong></span>', 'wp-event-aggregator' ) . '<br>';
362363
}else{
363-
$stats = '';
364+
if( $nothing_to_import ){
365+
$stats = '<span style="color: silver">'.__( 'No events are imported.', 'wp-event-aggregator' ).'</span>';
366+
}else{
367+
$stats = '';
368+
}
364369
}
365370
}
366371
}
@@ -467,6 +472,7 @@ function column_stats( $item ) {
467472
$updated = get_post_meta( $item['ID'], 'updated', true );
468473
$skipped = get_post_meta( $item['ID'], 'skipped', true );
469474
$skip_trash = get_post_meta( $item['ID'], 'skip_trash', true );
475+
$error_reason = get_post_meta( $item['ID'], 'error_reason', true );
470476
$nothing_to_import = get_post_meta( $item['ID'], 'nothing_to_import', true );
471477

472478
$success_message = '<span style="color: silver"><strong>';
@@ -482,8 +488,12 @@ function column_stats( $item ) {
482488
if( $skip_trash > 0 ){
483489
$success_message .= sprintf( __( '%d Skipped (Already exists in Trash)', 'wp-event-aggregator' ), $skip_trash ) ."<br>";
484490
}
485-
if( $nothing_to_import ){
486-
$success_message .= __( 'No events are imported.', 'wp-event-aggregator' ) . '<br>';
491+
if( !empty( $error_reason ) ){
492+
$success_message .= __( 'The Private token you provided was invalid.', 'import-eventbrite-events' ) . '<br>';
493+
}else{
494+
if( $nothing_to_import ){
495+
$success_message .= __( 'No events are imported.', 'import-eventbrite-events' ) . '<br>';
496+
}
487497
}
488498
$success_message .= "</strong></span>";
489499

languages/wp-event-aggregator.pot

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ msgstr ""
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
12-
"POT-Creation-Date: 2024-10-15T11:45:19+00:00\n"
12+
"POT-Creation-Date: 2024-10-15T11:51:04+00:00\n"
1313
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1414
"X-Generator: WP-CLI 2.11.0\n"
1515
"X-Domain: wp-event-aggregator\n"
@@ -73,7 +73,7 @@ msgid "Settings"
7373
msgstr ""
7474

7575
#: includes/class-wp-event-aggregator-admin.php:65
76-
#: includes/class-wp-event-aggregator-list-table.php:716
76+
#: includes/class-wp-event-aggregator-list-table.php:726
7777
msgid "Shortcode"
7878
msgstr ""
7979

@@ -286,7 +286,7 @@ msgstr ""
286286

287287
#: includes/class-wp-event-aggregator-admin.php:502
288288
#: includes/class-wp-event-aggregator-list-table.php:186
289-
#: includes/class-wp-event-aggregator-list-table.php:542
289+
#: includes/class-wp-event-aggregator-list-table.php:552
290290
msgid "Action"
291291
msgstr ""
292292

@@ -367,14 +367,14 @@ msgstr ""
367367
#: includes/class-wp-event-aggregator-common.php:544
368368
#: includes/class-wp-event-aggregator-list-table.php:132
369369
#: includes/class-wp-event-aggregator-list-table.php:345
370-
#: includes/class-wp-event-aggregator-list-table.php:474
370+
#: includes/class-wp-event-aggregator-list-table.php:480
371371
msgid "%d Created"
372372
msgstr ""
373373

374374
#: includes/class-wp-event-aggregator-common.php:547
375375
#: includes/class-wp-event-aggregator-list-table.php:135
376376
#: includes/class-wp-event-aggregator-list-table.php:348
377-
#: includes/class-wp-event-aggregator-list-table.php:477
377+
#: includes/class-wp-event-aggregator-list-table.php:483
378378
msgid "%d Updated"
379379
msgstr ""
380380

@@ -385,72 +385,76 @@ msgstr ""
385385
#: includes/class-wp-event-aggregator-common.php:553
386386
#: includes/class-wp-event-aggregator-list-table.php:141
387387
#: includes/class-wp-event-aggregator-list-table.php:354
388-
#: includes/class-wp-event-aggregator-list-table.php:483
388+
#: includes/class-wp-event-aggregator-list-table.php:489
389389
msgid "%d Skipped (Already exists in Trash)"
390390
msgstr ""
391391

392-
#: includes/class-wp-event-aggregator-common.php:618
392+
#: includes/class-wp-event-aggregator-common.php:557
393+
msgid "%d "
394+
msgstr ""
395+
396+
#: includes/class-wp-event-aggregator-common.php:624
393397
msgid "Once Hourly"
394398
msgstr ""
395399

396-
#: includes/class-wp-event-aggregator-common.php:621
400+
#: includes/class-wp-event-aggregator-common.php:627
397401
msgid "Twice Daily"
398402
msgstr ""
399403

400-
#: includes/class-wp-event-aggregator-common.php:624
404+
#: includes/class-wp-event-aggregator-common.php:630
401405
msgid "Once Daily"
402406
msgstr ""
403407

404-
#: includes/class-wp-event-aggregator-common.php:627
408+
#: includes/class-wp-event-aggregator-common.php:633
405409
msgid "Once Weekly"
406410
msgstr ""
407411

408-
#: includes/class-wp-event-aggregator-common.php:630
412+
#: includes/class-wp-event-aggregator-common.php:636
409413
msgid "Once a Month"
410414
msgstr ""
411415

412-
#: includes/class-wp-event-aggregator-common.php:685
416+
#: includes/class-wp-event-aggregator-common.php:691
413417
msgid "One-time Import"
414418
msgstr ""
415419

416-
#: includes/class-wp-event-aggregator-common.php:686
420+
#: includes/class-wp-event-aggregator-common.php:692
417421
#: includes/class-wp-event-aggregator-list-table.php:182
418422
msgid "Scheduled Import"
419423
msgstr ""
420424

421-
#: includes/class-wp-event-aggregator-common.php:740
425+
#: includes/class-wp-event-aggregator-common.php:746
422426
msgid "Status"
423427
msgstr ""
424428

425-
#: includes/class-wp-event-aggregator-common.php:745
429+
#: includes/class-wp-event-aggregator-common.php:751
426430
msgid "Published"
427431
msgstr ""
428432

429-
#: includes/class-wp-event-aggregator-common.php:748
433+
#: includes/class-wp-event-aggregator-common.php:754
430434
msgid "Pending"
431435
msgstr ""
432436

433-
#: includes/class-wp-event-aggregator-common.php:751
437+
#: includes/class-wp-event-aggregator-common.php:757
434438
msgid "Draft"
435439
msgstr ""
436440

437-
#: includes/class-wp-event-aggregator-common.php:854
441+
#: includes/class-wp-event-aggregator-common.php:860
438442
msgid "The Access Token has been invalidated because the user has changed their password, or Facebook has changed the session for security reasons. Please reauthorize your Facebook account from <strong>WP Event Aggregator</strong> > <strong> <a style=\"text-decoration: none;\" href=\""
439443
msgstr ""
440444

441-
#: includes/class-wp-event-aggregator-common.php:869
445+
#: includes/class-wp-event-aggregator-common.php:875
442446
msgid "The current \"WP Event Aggregator Pro\" add-on is not compatible with the Free plugin. Please update to Pro for flawless importing."
443447
msgstr ""
444448

445-
#: includes/class-wp-event-aggregator-common.php:883
449+
#: includes/class-wp-event-aggregator-common.php:889
446450
msgid "Available in Pro Add-on."
447451
msgstr ""
448452

449-
#: includes/class-wp-event-aggregator-common.php:883
453+
#: includes/class-wp-event-aggregator-common.php:889
450454
msgid "Upgrade to PRO"
451455
msgstr ""
452456

453-
#: includes/class-wp-event-aggregator-common.php:1367
457+
#: includes/class-wp-event-aggregator-common.php:1373
454458
msgid "Buy Tickets"
455459
msgstr ""
456460

@@ -746,22 +750,22 @@ msgstr ""
746750

747751
#: includes/class-wp-event-aggregator-eventbrite.php:60
748752
#: includes/class-wp-event-aggregator-eventbrite.php:73
749-
#: includes/class-wp-event-aggregator-eventbrite.php:97
753+
#: includes/class-wp-event-aggregator-eventbrite.php:102
750754
#: includes/class-wp-event-aggregator-tec.php:180
751755
#: includes/class-wp-event-aggregator-tec.php:252
752756
msgid "Something went wrong, please try again."
753757
msgstr ""
754758

755-
#: includes/class-wp-event-aggregator-eventbrite.php:116
759+
#: includes/class-wp-event-aggregator-eventbrite.php:121
756760
msgid "Please insert Eventbrite \"Personal OAuth token\"."
757761
msgstr ""
758762

759-
#: includes/class-wp-event-aggregator-eventbrite.php:128
763+
#: includes/class-wp-event-aggregator-eventbrite.php:133
760764
msgid "Please provide valid Eventbrite event ID: %s."
761765
msgstr ""
762766

763-
#: includes/class-wp-event-aggregator-eventbrite.php:137
764-
#: includes/class-wp-event-aggregator-eventbrite.php:147
767+
#: includes/class-wp-event-aggregator-eventbrite.php:142
768+
#: includes/class-wp-event-aggregator-eventbrite.php:158
765769
msgid "Something went wrong with Eventbrite event ID: %s, please try again."
766770
msgstr ""
767771

@@ -817,14 +821,14 @@ msgstr ""
817821

818822
#: includes/class-wp-event-aggregator-list-table.php:76
819823
#: includes/class-wp-event-aggregator-list-table.php:194
820-
#: includes/class-wp-event-aggregator-list-table.php:446
821-
#: includes/class-wp-event-aggregator-list-table.php:550
824+
#: includes/class-wp-event-aggregator-list-table.php:451
825+
#: includes/class-wp-event-aggregator-list-table.php:560
822826
msgid "Delete"
823827
msgstr ""
824828

825829
#: includes/class-wp-event-aggregator-list-table.php:94
826830
#: includes/class-wp-event-aggregator-list-table.php:106
827-
#: includes/class-wp-event-aggregator-list-table.php:453
831+
#: includes/class-wp-event-aggregator-list-table.php:458
828832
msgid "Origin"
829833
msgstr ""
830834

@@ -842,7 +846,7 @@ msgstr ""
842846

843847
#: includes/class-wp-event-aggregator-list-table.php:138
844848
#: includes/class-wp-event-aggregator-list-table.php:351
845-
#: includes/class-wp-event-aggregator-list-table.php:480
849+
#: includes/class-wp-event-aggregator-list-table.php:486
846850
msgid "%d Skipped"
847851
msgstr ""
848852

@@ -863,7 +867,7 @@ msgid "Import Event Status"
863867
msgstr ""
864868

865869
#: includes/class-wp-event-aggregator-list-table.php:184
866-
#: includes/class-wp-event-aggregator-list-table.php:539
870+
#: includes/class-wp-event-aggregator-list-table.php:549
867871
msgid "Import Category"
868872
msgstr ""
869873

@@ -879,40 +883,43 @@ msgstr ""
879883
msgid "Last Import Stats: "
880884
msgstr ""
881885

882-
#: includes/class-wp-event-aggregator-list-table.php:361
883-
#: includes/class-wp-event-aggregator-list-table.php:486
886+
#: includes/class-wp-event-aggregator-list-table.php:362
887+
msgid "<span style=\"color: red\"><strong>The Private token you provided was invalid.</strong></span>"
888+
msgstr ""
889+
890+
#: includes/class-wp-event-aggregator-list-table.php:365
884891
msgid "No events are imported."
885892
msgstr ""
886893

887-
#: includes/class-wp-event-aggregator-list-table.php:515
894+
#: includes/class-wp-event-aggregator-list-table.php:525
888895
msgid "View Imported Events"
889896
msgstr ""
890897

891-
#: includes/class-wp-event-aggregator-list-table.php:538
898+
#: includes/class-wp-event-aggregator-list-table.php:548
892899
msgid "Import"
893900
msgstr ""
894901

895-
#: includes/class-wp-event-aggregator-list-table.php:540
902+
#: includes/class-wp-event-aggregator-list-table.php:550
896903
msgid "Import Date"
897904
msgstr ""
898905

899-
#: includes/class-wp-event-aggregator-list-table.php:541
906+
#: includes/class-wp-event-aggregator-list-table.php:551
900907
msgid "Import Stats"
901908
msgstr ""
902909

903-
#: includes/class-wp-event-aggregator-list-table.php:575
910+
#: includes/class-wp-event-aggregator-list-table.php:585
904911
msgid "Warning! Import history will be permanatly deleted. Are you certain you want to delete the import history?"
905912
msgstr ""
906913

907-
#: includes/class-wp-event-aggregator-list-table.php:578
914+
#: includes/class-wp-event-aggregator-list-table.php:588
908915
msgid "Clear Import History"
909916
msgstr ""
910917

911-
#: includes/class-wp-event-aggregator-list-table.php:714
918+
#: includes/class-wp-event-aggregator-list-table.php:724
912919
msgid "ID"
913920
msgstr ""
914921

915-
#: includes/class-wp-event-aggregator-list-table.php:715
922+
#: includes/class-wp-event-aggregator-list-table.php:725
916923
msgid "Title"
917924
msgstr ""
918925

0 commit comments

Comments
 (0)