PluginProbe
Route ‑ Shipping Protection / 2.3.0
Route ‑ Shipping Protection v2.3.0
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-admin.php

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

171 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The admin-specific functionality of the plugin.
5 *
6 * @link https://route.com/
7 * @since 1.0.0
8 *
9 * @package Routeapp
10 * @subpackage Routeapp/admin
11 */
12
13 /**
14 * The admin-specific functionality of the plugin.
15 *
16 *
17 * @package Routeapp
18 * @subpackage Routeapp/admin
19 * @author Route App <support@route.com>
20 */
21 class Routeapp_Admin {
22
23 /**
24 * The ID of this plugin.
25 *
26 * @since 1.0.0
27 * @access private
28 * @var string $plugin_name The ID of this plugin.
29 */
30 private $plugin_name;
31
32 /**
33 * The version of this plugin.
34 *
35 * @since 1.0.0
36 * @access private
37 * @var string $version The current version of this plugin.
38 */
39 private $version;
40
41 private $routeapp_webhooks;
42
43 /**
44 * Initialize the class and set its properties.
45 *
46 * @since 1.0.0
47 * @param string $plugin_name The name of this plugin.
48 * @param string $version The version of this plugin.
49 */
50 public function __construct( $plugin_name, $version ) {
51 $this->plugin_name = $plugin_name;
52 $this->version = $version;
53 $this->routeapp_webhooks = new Routeapp_Webhooks();
54
55 add_filter( 'woocommerce_get_settings_pages', array( $this, 'routeapp_add_settings' ), 15 );
56 add_filter( 'woocommerce_get_settings_pages', array( $this, 'routeapp_add_order_recover_settings' ), 15 );
57 add_filter( 'plugin_action_links', array( $this, 'get_action_links' ), 10, 2 );
58 add_filter( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ));
59
60 //check webhooks
61 add_action('admin_init', [$this, 'upsert_webhooks']);
62
63 }
64
65
66 private function _is_routedata_complete()
67 {
68 $merchant_id = get_option('routeapp_merchant_id', false);
69 $secret_token = get_option('routeapp_secret_token', false);
70 return $merchant_id && $secret_token;
71 }
72
73 public function upsert_webhooks() {
74 //only check for webhooks if we have merchant id and secret token on database
75 if ($this->_is_routedata_complete()) {
76 $upsertWebhooks = get_option('_routeapp_webhooks_created', false);
77 //only upsert webhooks if we cannot find flag
78 if (!$upsertWebhooks) {
79 $this->routeapp_webhooks->upsert_webhooks();
80 }
81 }
82 }
83
84 /**
85 * Register the stylesheets for the admin area.
86 *
87 * @since 1.0.0
88 */
89 public function enqueue_styles() {
90 wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/routeapp-admin.css', array(), $this->version, 'all' );
91 }
92
93 /**
94 * Register the JavaScript for the admin area.
95 *
96 * @since 1.0.0
97 */
98 public function enqueue_scripts() {
99 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/routeapp-admin.js', array( 'jquery' ), $this->version, false );
100 }
101
102 /**
103 * Create settings tab in Woocommerce settings
104 *
105 * @since 1.0.0
106 */
107 public function routeapp_add_settings($settings) {
108 require_once plugin_dir_path( __FILE__ ) . 'class-wc-settings-routeapp.php';
109 $retArray = [];
110 if (is_object($settings)) {
111 $retArray[] = $settings;
112 } else {
113 $retArray = $settings;
114 }
115 $retArray[] = new WC_Settings_Routeapp();
116
117 return $retArray;
118 }
119
120 /**
121 * Create order recover settings tab in Woocommerce settings
122 *
123 */
124 public function routeapp_add_order_recover_settings($settings) {
125 require_once plugin_dir_path( __FILE__ ) . 'class-wc-settings-routeapp-order-recover.php';
126 $retArray = [];
127 if (is_object($settings)) {
128 $retArray[] = $settings;
129 } else {
130 $retArray = $settings;
131 }
132 $retArray[] = new WC_Settings_Routeapp_Order_Recover();
133 return $retArray;
134 }
135
136
137 /**
138 * Create extra action links to Plugin settings
139 *
140 * @since 1.0.0
141 */
142 public function get_action_links( $links, $file ) {
143 $base = explode( '/', plugin_basename( __FILE__ ) );
144 $file = explode( '/', $file );
145
146 if( $base[0] === $file[0] ) {
147 $extraLinks = array(
148 sprintf('<a href="%s">%s</a>', admin_url( 'admin.php?page=wc-settings&tab=routeapp' ), __( 'Settings', 'routeapp' ))
149 );
150 $links = array_merge($links, $extraLinks);
151 }
152
153 return (array) array_reverse($links);
154 }
155
156 public function display_admin_notices() {
157
158 $screen = get_current_screen();
159
160 if ( $screen->id === 'woocommerce_page_wc-settings' && isset($_GET['tab']) && $_GET['tab'] === 'routeapp' ) {
161
162 $class = 'notice notice-info';
163 $message = __( 'Open the <a href="https://dashboard.routeapp.io/" target="_blank">Route Partner Portal</a> to view claim details.', 'routeapp' );
164
165 printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
166
167 }
168 }
169
170 }
171