| @@ -11,9 +11,8 @@ | ||
| 11 | 11 | */ |
| 12 | 12 | public static function init() { |
| 13 | 13 | add_action( 'admin_menu', array( __CLASS__ , 'setup_admin_page') ); |
| 14 | 14 | add_action( 'admin_init', array( __CLASS__ , 'handle_webhook_validation_form' ) ); |
| 15 | - add_action( 'admin_init', array( __CLASS__ , 'handle_save_triggers_form' ) ); | |
| 16 | 15 | } |
| 17 | 16 | |
| 18 | 17 | /** |
| 19 | 18 | * Add dashboard page to admin menu |
| @@ -57,14 +56,13 @@ | ||
| 57 | 56 | update_option('notifier_api_key', $api_key); |
| 58 | 57 | delete_option('notifier_enabled_triggers'); |
| 59 | 58 | |
| 60 | 59 | $params = array( |
| 61 | - 'action' => 'verify_api', | |
| 62 | 60 | 'site_url' => site_url(), |
| 63 | 61 | 'source' => 'wp' |
| 64 | 62 | ); |
| 65 | 63 | |
| 66 | - $response = Notifier::send_api_request( $params, 'POST' ); | |
| 64 | + $response = Notifier::send_api_request( 'verify_api', $params, 'POST' ); | |
| 67 | 65 | |
| 68 | 66 | if($response->error){ |
| 69 | 67 | $notices[] = array( |
| 70 | 68 | 'message' => $response->message, |
| @@ -75,65 +73,8 @@ | ||
| 75 | 73 | die; |
| 76 | 74 | } |
| 77 | 75 | |
| 78 | 76 | update_option('notifier_api_activated', 'yes'); |
| 79 | - | |
| 80 | - $notices[] = array( | |
| 81 | - 'message' => $response->data, | |
| 82 | - 'type' => 'success' | |
| 83 | - ); | |
| 84 | - new Notifier_Admin_Notices($notices, true); | |
| 85 | - wp_redirect(admin_url('admin.php?page=notifier')); | |
| 86 | - die; | |
| 87 | - | |
| 88 | - } | |
| 89 | - | |
| 90 | - /** | |
| 91 | - * Handle save triggers form | |
| 92 | - */ | |
| 93 | - public static function handle_save_triggers_form () { | |
| 94 | - if ( ! isset( $_POST['notifier_save_triggers'] ) ) { | |
| 95 | - return; | |
| 96 | - } | |
| 97 | - | |
| 98 | - //phpcs:ignore | |
| 99 | - if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], NOTIFIER_NAME . '-save-triggers' ) ) { | |
| 100 | - return; | |
| 101 | - } | |
| 102 | - | |
| 103 | - $notifier_triggers = (!empty($_POST['notifier_triggers'])) ? notifier_sanitize_array($_POST['notifier_triggers']) : array(); | |
| 104 | - $all_triggers = Notifier_Notification_Triggers::get_notification_triggers(); | |
| 105 | - $selected_triggers = array(); | |
| 106 | - foreach ($all_triggers as $key => $triggers) { | |
| 107 | - foreach ($triggers as $trigger){ | |
| 108 | - if( ! in_array($trigger['id'], $notifier_triggers) ){ | |
| 109 | - continue; | |
| 110 | - } | |
| 111 | - unset($trigger['action']); | |
| 112 | - $selected_triggers[$key][] = $trigger; | |
| 113 | - } | |
| 114 | - } | |
| 115 | - | |
| 116 | - $params = array( | |
| 117 | - 'action' => 'update_triggers', | |
| 118 | - 'site_url' => site_url(), | |
| 119 | - 'source' => 'wp', | |
| 120 | - 'triggers' => $selected_triggers | |
| 121 | - ); | |
| 122 | - | |
| 123 | - $response = Notifier::send_api_request( $params, 'POST' ); | |
| 124 | - | |
| 125 | - if($response->error){ | |
| 126 | - $notices[] = array( | |
| 127 | - 'message' => $response->message, | |
| 128 | - 'type' => 'error' | |
| 129 | - ); | |
| 130 | - new Notifier_Admin_Notices($notices, true); | |
| 131 | - wp_redirect(admin_url('admin.php?page=notifier')); | |
| 132 | - die; | |
| 133 | - } | |
| 134 | - | |
| 135 | - update_option('notifier_enabled_triggers', $notifier_triggers); | |
| 136 | 77 | |
| 137 | 78 | $notices[] = array( |
| 138 | 79 | 'message' => $response->data, |
| 139 | 80 | 'type' => 'success' |