Skip to content

Commit 80a4977

Browse files
Merge pull request #2 from burningmantech/feat-php-82
Refactor for PHP 8.2
2 parents d172950 + 5632080 commit 80a4977

File tree

5 files changed

+485
-477
lines changed

5 files changed

+485
-477
lines changed

assets/js/woocommerce-cart-error-dom.js

-19
This file was deleted.

class-settings.php

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
class wp_slack_woocommerce_settings extends wp_slack_woocommerce
3+
{
4+
public function init()
5+
{
6+
add_filter('woocommerce_settings_tabs_array', array($this, 'woo_new_section_tabs'), 50);
7+
add_action('woocommerce_settings_tabs_settings_slack_woocommerce', array($this, 'settings_tab'));
8+
add_action('woocommerce_update_options_settings_slack_woocommerce', array($this, 'update_settings'));
9+
}
10+
11+
public static function get_settings()
12+
{
13+
$settings = array(
14+
'section_title' => array(
15+
'name' => __('Slack Notifications', 'wp-slack-woocommerce'),
16+
'type' => 'title',
17+
'desc' => '',
18+
'id' => 'wc_settings_tab_slack_woocommerce_title'
19+
),
20+
'notifications_enable' => array(
21+
'name' => __('Enable Notifications', 'wp-slack-woocommerce'),
22+
'type' => 'checkbox',
23+
'desc' => __('Enable Slack Notifications using the settings below', 'wp-slack-woocommerce'),
24+
'id' => 'wc_settings_tab_slack_woocommerce_enable_notifications'
25+
),
26+
27+
'title' => array(
28+
'name' => __('Slack Token', 'wp-slack-woocommerce'),
29+
'type' => 'text',
30+
'desc' => __('', 'wp-slack-woocommerce'),
31+
'id' => 'wc_settings_tab_slack_token'
32+
),
33+
'channel' => array(
34+
'name' => __('Slack Channel', 'wp-slack-woocommerce'),
35+
'type' => 'text',
36+
'desc' => __('', 'wp-slack-woocommerce'),
37+
'id' => 'wc_settings_tab_slack_woocommerce_channel'
38+
),
39+
'icon-confirm' => array(
40+
'name' => __('Confirmed Icon', 'wp-slack-woocommerce'),
41+
'type' => 'text',
42+
'desc' => __('', 'wp-slack-woocommerce'),
43+
'id' => 'wc_settings_tab_slack_woocommerce_slack_icon_completed'
44+
),
45+
'icon-cancel' => array(
46+
'name' => __('Cancelled Icon', 'wp-slack-woocommerce'),
47+
'type' => 'text',
48+
'desc' => __('', 'wp-slack-woocommerce'),
49+
'id' => 'wc_settings_tab_slack_woocommerce_slack_icon_cancelled'
50+
),
51+
'icon-fail' => array(
52+
'name' => __('Failed Icon', 'wp-slack-woocommerce'),
53+
'type' => 'text',
54+
'desc' => __('', 'wp-slack-woocommerce'),
55+
'id' => 'wc_settings_tab_slack_woocommerce_slack_icon_failed'
56+
),
57+
'test_slack' => array(
58+
'name' => __('', 'wp-slack-woocommerce'),
59+
'type' => 'title',
60+
'desc' => '<a href="#" id="test_slack">Test slack</a>',
61+
'id' => 'wc_settings_tab_slack_test_slack'
62+
),
63+
'section_end' => array(
64+
'type' => 'sectionend',
65+
'id' => 'wc_settings_tab_slack_woocommerce_end'
66+
)
67+
);
68+
return apply_filters('wc_settings_tab_slack_woocommerce', $settings);
69+
}
70+
public function woo_new_section_tabs($sections)
71+
{
72+
$sections['settings_slack_woocommerce'] = __('Slack Notifications', 'wp-slack-woocommerce');
73+
return $sections;
74+
}
75+
public function update_settings()
76+
{
77+
woocommerce_update_options($this->get_settings());
78+
}
79+
public function settings_tab()
80+
{
81+
woocommerce_admin_fields($this->get_settings());
82+
}
83+
}

class-testmode.php

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<?php
2+
class wp_slack_woocommerce_testmode extends wp_slack_woocommerce
3+
{
4+
public function init()
5+
{
6+
$plugin_path = 'woocommerce-click-pledge-gateway/gateway-clickandpledge.php';
7+
if (
8+
(is_plugin_active($plugin_path) || is_plugin_inactive($plugin_path))
9+
&& file_exists(ABSPATH . '/wp-content/plugins/' . $plugin_path)
10+
) {
11+
add_action('deactivate_' . $plugin_path, array($this, 'clickandpledge_deactivate'));
12+
add_action('activate_' . $plugin_path, array($this, 'clickandpledge_activate'));
13+
}
14+
15+
$plugin_path = 'woocommerce-gateway-firstdata/woocommerce-gateway-first-data.php';
16+
if (
17+
(is_plugin_active($plugin_path) || is_plugin_inactive($plugin_path))
18+
&& file_exists(ABSPATH . '/wp-content/plugins/' . $plugin_path)
19+
) {
20+
add_action('deactivate_' . $plugin_path, array($this, 'payeezy_deactivate'));
21+
add_action('activate_' . $plugin_path, array($this, 'payeezy_activate'));
22+
}
23+
24+
add_action('woocommerce_update_options', array($this, 'testmode_check'), 10, 1);
25+
add_action('testmode_check', array($this, 'testmode_check'));
26+
}
27+
28+
/**
29+
* Checks the test mode status of Payeezy and Click and Pledge gateways.
30+
*
31+
* This function checks if the specified WooCommerce gateways (Payeezy and Click and Pledge)
32+
* are active or inactive and whether their respective plugin files exist. If the conditions
33+
* are met, it calls respective functions to check the test mode status of these gateways.
34+
*/
35+
public function testmode_check()
36+
{
37+
$plugin_path = 'woocommerce-gateway-firstdata/woocommerce-gateway-first-data.php';
38+
if (
39+
(is_plugin_active($plugin_path) || is_plugin_inactive($plugin_path))
40+
&& file_exists(ABSPATH . '/wp-content/plugins/' . $plugin_path)
41+
) {
42+
$this->payeezy_testmode_check();
43+
}
44+
45+
$plugin_path = 'woocommerce-click-pledge-gateway/gateway-clickandpledge.php';
46+
if (
47+
(is_plugin_active($plugin_path) || is_plugin_inactive($plugin_path))
48+
&& file_exists(ABSPATH . '/wp-content/plugins/' . $plugin_path)
49+
) {
50+
$this->clickandpledge_testmode_check();
51+
}
52+
}
53+
54+
public function payeezy_activate()
55+
{
56+
$message = " Production website's Production website's Payeezy Gateway is active!";
57+
$icon = ":heavy_check_mark:";
58+
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
59+
$this->slack_message($message, "Payeezy Gateway Plugin Active", $channel, $icon);
60+
}
61+
public function payeezy_deactivate()
62+
{
63+
$message = "WARNING: Production website's Production website's Payeezy Gateway is in not active!";
64+
$icon = ":warning:";
65+
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
66+
$this->slack_message($message, "Payeezy Gateway Plugin Inactive", $channel, $icon);
67+
}
68+
public function payeezy_testmode_check()
69+
{
70+
// Don't check for WPEngine yet, need to test first
71+
$settings = get_option('woocommerce_first_data_payeezy_gateway_credit_card_settings');
72+
if ($settings['environment'] == 'demo' && get_option('woocommerce_pe_testmode') != 'true') {
73+
update_option('woocommerce_pe_testmode', 'true');
74+
$message = "WARNING: Production website's Payeezy Gateway Environment is set to Demo";
75+
$icon = ":warning:";
76+
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
77+
$this->slack_message($message, "Payeezy Gateway Environment set to Demo", $channel, $icon);
78+
} else if ($settings['environment'] == 'production') {
79+
if (get_option('woocommerce_pe_testmode') == 'true') {
80+
$message = "Production website's Payeezy Gateway Environment is set to Production";
81+
$icon = ":heavy_check_mark:";
82+
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
83+
$this->slack_message($message, "Payeezy Environment set to Production", $channel, $icon);
84+
}
85+
update_option('woocommerce_pe_testmode', 'false');
86+
}
87+
88+
if ($settings['enabled'] == 'no' && get_option('woocommerce_pe_enabled') != 'false') {
89+
update_option('woocommerce_pe_enabled', 'false');
90+
$message = "WARNING: Production website's Payeezy Gateway is not enabled";
91+
$icon = ":warning:";
92+
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
93+
$this->slack_message($message, "Payeezy disabled", $channel, $icon);
94+
} else if ($settings['enabled'] == 'yes') {
95+
if (get_option('woocommerce_pe_enabled') == 'false') {
96+
$message = "Production website's Payeezy Gateway is enabled";
97+
$icon = ":heavy_check_mark:";
98+
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
99+
$this->slack_message($message, "Payeezy Gateway enabled", $channel, $icon);
100+
}
101+
update_option('woocommerce_pe_enabled', 'true');
102+
}
103+
}
104+
public function clickandpledge_activate()
105+
{
106+
$message = " Production website's Click and Pledge Gateway is active!";
107+
$icon = ":heavy_check_mark:";
108+
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
109+
$this->slack_message($message, "Click and Pledge Active", $channel, $icon);
110+
}
111+
public function clickandpledge_deactivate()
112+
{
113+
$message = "WARNING: Production website's Click and Pledge Gateway is in not active!";
114+
$icon = ":warning:";
115+
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
116+
$this->slack_message($message, "Click and Pledge Inactive", $channel, $icon);
117+
}
118+
public function clickandpledge_testmode_check()
119+
{
120+
if (is_wpe()) {
121+
$settings = get_option('woocommerce_clickandpledge_settings');
122+
$p_settings = get_option('woocommerce_clickandpledge_paymentsettings');
123+
124+
if ($p_settings['testmode'] == 'yes') {
125+
update_option('woocommerce_cp_testmode', 'true');
126+
$message = "WARNING: Production website's Click and Pledge Gateway is in Testmode";
127+
$icon = ":warning:";
128+
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
129+
$this->slack_message($message, "Click and Pledge in Testmode", $channel, $icon);
130+
} else {
131+
if (get_option('woocommerce_cp_testmode') == 'true') {
132+
$message = "Production website's Click and Pledge Gateway is in Production";
133+
$icon = ":heavy_check_mark:";
134+
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
135+
$this->slack_message($message, "Click and Pledge in Production", $channel, $icon);
136+
}
137+
update_option('woocommerce_cp_testmode', 'false');
138+
}
139+
140+
if ($p_settings['enabled'] == 'yes') {
141+
if (get_option('woocommerce_cp_enabled') == 'false') {
142+
$message = "Production website's Click and Pledge Gateway is enabled";
143+
$icon = ":heavy_check_mark:";
144+
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
145+
$this->slack_message($message, "Click and Pledge enabled", $channel, $icon);
146+
}
147+
update_option('woocommerce_cp_enabled', 'true');
148+
149+
} else {
150+
update_option('woocommerce_cp_enabled', 'false');
151+
$message = "WARNING: Production website's Click and Pledge Gateway is not enabled";
152+
$icon = ":warning:";
153+
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
154+
$this->slack_message($message, "Click and Pledge disabled", $channel, $icon);
155+
}
156+
157+
}
158+
159+
}
160+
161+
}

composer.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "burningmantech/woocommerce-slack-notifications",
3+
"description": "Trigger slack notifications when a WooCommerce order status is updated to canceled or completed.",
4+
"type": "wordpress-plugin",
5+
"require": {
6+
"php": "^7.4 || ^8.0"
7+
},
8+
"require-dev": {
9+
}
10+
}

0 commit comments

Comments
 (0)