PluginProbe
Route ‑ Shipping Protection / 2.2.5
Route ‑ Shipping Protection v2.2.5
2.4.17 2.4.16 2.4.15 2.4.14 2.4.13 2.4.12 2.4.11 2.4.10 2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.2.4 2.2.5 2.2.6 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 All 151 releases
routeapp / admin / class-routeapp-notice.php

class-routeapp-notice.php in Route ‑ Shipping Protection 2.2.5, at admin/class-routeapp-notice.php

146 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The file that defines the core plugin class
5 *
6 * A class definition that includes attributes and functions used across both the
7 * public-facing side of the site and the admin area.
8 *
9 * @link https://route.com/
10 * @since 1.0.4
11 *
12 * @package Routeapp
13 * @subpackage Routeapp/admin
14 */
15
16 class Routeapp_Notice {
17
18 public function __construct( ) {
19 add_action( 'admin_notices', array( $this, 'routeapp_attention_required' ) );
20 add_action('network_admin_notices', array( $this, 'routeapp_attention_required' ) );
21 }
22
23 /**
24 * Add admin notice messages to Woocommerce
25 * @since 1.0.4
26 * @param string $message Message that would be output
27 * @param string $notification_type (success, warning, danger, info)
28 * @param void
29 */
30 public function add_notice($message, $notification_type) {
31 echo sprintf('<div class="notice %s is-dismissible"><p><span class="dashicons-before dashicons-arkcommerce" style="vertical-align:middle;"> </span> %s</p></div>', $this->get_notice_class($notification_type), $message);
32 }
33
34 /**
35 * Get notice class name
36 * @since 1.0.4
37 * @param string $notification_type (success, warning, danger, info)
38 * @param string $className
39 */
40 public function get_notice_class($notification_type = 'success') {
41 return "notice-{$notification_type}";
42 }
43
44 /**
45 * Import all admin notices message
46 * @since 1.0.4
47 * @param void
48 */
49 public function routeapp_attention_required()
50 {
51 $this->billing_attention_required();
52 $this->user_attention_required();
53 $this->merchant_attention_required();
54 $this->redirect_attention_required();
55 }
56
57 /**
58 * Import admin notice verification to Billing Info
59 * @since 1.0.4
60 * @param void
61 */
62 public function billing_attention_required()
63 {
64 $billingResponse = Routeapp_API_Client::getInstance()->get_billing();
65
66 if (!is_wp_error($billingResponse)) {
67 $body = json_decode($billingResponse['body']);
68
69 if (isset($body) && is_countable($body)) {
70 if (count($body) === 0) {
71 $this->add_notice("Route: You haven't yet completed the Billing Info step. Click <a href='http://dashboard.route.com/admin/preferences' target='_blank'>here</a> to complete.", "warning");
72 }
73 }
74 }
75 }
76
77 /**
78 * Import admin notice if user creation has failed
79 * @since 1.0.4
80 * @param void
81 */
82 public function user_attention_required()
83 {
84 $routeapp_public = $this->get_route_public_instance();
85 if ($routeapp_public->has_user_creation_conflicted()) {
86 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/routeapp-admin-user-conflict.php';
87 }
88 if ($routeapp_public->has_user_creation_failed()) {
89 $this->add_notice("We couldn't create your account, please contact our support or <a href=\"/wp-json/route/recreate_user\"> try again </a></span>.", "warning");
90 }
91 }
92
93 /**
94 * @return WP_User
95 */
96 private function get_current_user()
97 {
98 return wp_get_current_user();
99 }
100
101 /**
102 * @return string
103 */
104 private function get_current_email()
105 {
106 return get_bloginfo('admin_email');
107 }
108
109 /**
110 * Import admin notice if merchant creation has failed
111 * @since 1.0.4
112 * @param void
113 */
114 public function merchant_attention_required()
115 {
116 $routeapp_public = $this->get_route_public_instance();
117 if ($routeapp_public->has_merchant_creation_failed()) {
118 $this->add_notice("Route merchant creation has failed. Please click <a href=\"/wp-json/route/recreate_merchant\"> here </a> to retry</span>.", "warning");
119 }
120 }
121
122 /**
123 * Import admin notice verification to Billing Info
124 * @since 1.0.4
125 * @param void
126 */
127 public function redirect_attention_required()
128 {
129 $routeapp_public = $this->get_route_public_instance();
130 if ($routeapp_public->successful_registration() && !$routeapp_public->was_redirected()) {
131 $this->add_notice("You're almost there! We're redirecting you to Route website to finalize your account setup... <span id=\"route_counter\" data-redirect-src=\"". Route_Setup::get_route_redirect() ."\">5</span>", "success");
132 $routeapp_public->set_as_redirected();
133 }
134 if ($routeapp_public->has_merchant_creation_conflicted()) {
135 $this->add_notice("Your merchant account already exists. We're redirecting you to Route website to finalize your account setup...<span id=\"route_counter\" data-redirect-src=\"". Route_Setup::get_route_redirect() ."\">5</span>.", "warning");
136 }
137 }
138
139 private function get_route_public_instance()
140 {
141 global $routeapp_public;
142 return $routeapp_public;
143 }
144
145 }
146