PluginProbe
WANotifier for Forms and Actions / 2.1.3
WANotifier for Forms and Actions v2.1.3
3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 1.0.3 All 66 releases
notifier / includes / classes / class-notifier-dashboard.php

class-notifier-dashboard.php in WANotifier for Forms and Actions 2.1.3, at includes/classes/class-notifier-dashboard.php

89 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin dashboard page class
4 *
5 * @package Wa_Notifier
6 */
7 class Notifier_Dashboard {
8
9 /**
10 * Init
11 */
12 public static function init() {
13 add_action( 'admin_menu', array( __CLASS__ , 'setup_admin_page') );
14 add_action( 'admin_init', array( __CLASS__ , 'handle_webhook_validation_form' ) );
15 }
16
17 /**
18 * Add dashboard page to admin menu
19 */
20 public static function setup_admin_page () {
21 add_menu_page( 'WA Notifier', 'WA Notifier', 'manage_options', NOTIFIER_NAME, array( __CLASS__ , 'output'), 'dashicons-megaphone', '51' );
22 }
23
24 /**
25 * Output
26 */
27 public static function output() {
28 include_once NOTIFIER_PATH . '/views/admin-dashboard.php';
29 }
30
31 /**
32 * Handle displaimer form
33 */
34 public static function handle_webhook_validation_form () {
35 if ( ! isset( $_POST['webhook_validation'] ) ) {
36 return;
37 }
38
39 //phpcs:ignore
40 if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], NOTIFIER_NAME . '-webhook-validation' ) ) {
41 return;
42 }
43
44 $api_key = (isset($_POST['notifier_api_key'])) ? sanitize_text_field(wp_unslash($_POST['notifier_api_key'])) : '';
45
46 if('' == trim($api_key)) {
47 $notices[] = array(
48 'message' => 'Please enter API key.',
49 'type' => 'error'
50 );
51 new Notifier_Admin_Notices($notices, true);
52 wp_redirect(admin_url('admin.php?page=notifier'));
53 die;
54 }
55
56 update_option('notifier_api_key', $api_key);
57 delete_option('notifier_enabled_triggers');
58
59 $params = array(
60 'site_url' => site_url(),
61 'source' => 'wp'
62 );
63
64 $response = Notifier::send_api_request( 'verify_api', $params, 'POST' );
65
66 if($response->error){
67 $notices[] = array(
68 'message' => $response->message,
69 'type' => 'error'
70 );
71 new Notifier_Admin_Notices($notices, true);
72 wp_redirect(admin_url('admin.php?page=notifier'));
73 die;
74 }
75
76 update_option('notifier_api_activated', 'yes');
77
78 $notices[] = array(
79 'message' => $response->data,
80 'type' => 'success'
81 );
82 new Notifier_Admin_Notices($notices, true);
83 wp_redirect(admin_url('admin.php?page=notifier'));
84 die;
85
86 }
87
88 }
89