Skip to content

Commit

Permalink
Merge pull request #2 from burningmantech/feat-php-82
Browse files Browse the repository at this point in the history
Refactor for PHP 8.2
  • Loading branch information
trevorbicewebdesign authored Nov 17, 2023
2 parents d172950 + 5632080 commit 80a4977
Show file tree
Hide file tree
Showing 5 changed files with 485 additions and 477 deletions.
19 changes: 0 additions & 19 deletions assets/js/woocommerce-cart-error-dom.js

This file was deleted.

83 changes: 83 additions & 0 deletions class-settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
class wp_slack_woocommerce_settings extends wp_slack_woocommerce
{
public function init()
{
add_filter('woocommerce_settings_tabs_array', array($this, 'woo_new_section_tabs'), 50);
add_action('woocommerce_settings_tabs_settings_slack_woocommerce', array($this, 'settings_tab'));
add_action('woocommerce_update_options_settings_slack_woocommerce', array($this, 'update_settings'));
}

public static function get_settings()
{
$settings = array(
'section_title' => array(
'name' => __('Slack Notifications', 'wp-slack-woocommerce'),
'type' => 'title',
'desc' => '',
'id' => 'wc_settings_tab_slack_woocommerce_title'
),
'notifications_enable' => array(
'name' => __('Enable Notifications', 'wp-slack-woocommerce'),
'type' => 'checkbox',
'desc' => __('Enable Slack Notifications using the settings below', 'wp-slack-woocommerce'),
'id' => 'wc_settings_tab_slack_woocommerce_enable_notifications'
),

'title' => array(
'name' => __('Slack Token', 'wp-slack-woocommerce'),
'type' => 'text',
'desc' => __('', 'wp-slack-woocommerce'),
'id' => 'wc_settings_tab_slack_token'
),
'channel' => array(
'name' => __('Slack Channel', 'wp-slack-woocommerce'),
'type' => 'text',
'desc' => __('', 'wp-slack-woocommerce'),
'id' => 'wc_settings_tab_slack_woocommerce_channel'
),
'icon-confirm' => array(
'name' => __('Confirmed Icon', 'wp-slack-woocommerce'),
'type' => 'text',
'desc' => __('', 'wp-slack-woocommerce'),
'id' => 'wc_settings_tab_slack_woocommerce_slack_icon_completed'
),
'icon-cancel' => array(
'name' => __('Cancelled Icon', 'wp-slack-woocommerce'),
'type' => 'text',
'desc' => __('', 'wp-slack-woocommerce'),
'id' => 'wc_settings_tab_slack_woocommerce_slack_icon_cancelled'
),
'icon-fail' => array(
'name' => __('Failed Icon', 'wp-slack-woocommerce'),
'type' => 'text',
'desc' => __('', 'wp-slack-woocommerce'),
'id' => 'wc_settings_tab_slack_woocommerce_slack_icon_failed'
),
'test_slack' => array(
'name' => __('', 'wp-slack-woocommerce'),
'type' => 'title',
'desc' => '<a href="#" id="test_slack">Test slack</a>',
'id' => 'wc_settings_tab_slack_test_slack'
),
'section_end' => array(
'type' => 'sectionend',
'id' => 'wc_settings_tab_slack_woocommerce_end'
)
);
return apply_filters('wc_settings_tab_slack_woocommerce', $settings);
}
public function woo_new_section_tabs($sections)
{
$sections['settings_slack_woocommerce'] = __('Slack Notifications', 'wp-slack-woocommerce');
return $sections;
}
public function update_settings()
{
woocommerce_update_options($this->get_settings());
}
public function settings_tab()
{
woocommerce_admin_fields($this->get_settings());
}
}
161 changes: 161 additions & 0 deletions class-testmode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php
class wp_slack_woocommerce_testmode extends wp_slack_woocommerce
{
public function init()
{
$plugin_path = 'woocommerce-click-pledge-gateway/gateway-clickandpledge.php';
if (
(is_plugin_active($plugin_path) || is_plugin_inactive($plugin_path))
&& file_exists(ABSPATH . '/wp-content/plugins/' . $plugin_path)
) {
add_action('deactivate_' . $plugin_path, array($this, 'clickandpledge_deactivate'));
add_action('activate_' . $plugin_path, array($this, 'clickandpledge_activate'));
}

$plugin_path = 'woocommerce-gateway-firstdata/woocommerce-gateway-first-data.php';
if (
(is_plugin_active($plugin_path) || is_plugin_inactive($plugin_path))
&& file_exists(ABSPATH . '/wp-content/plugins/' . $plugin_path)
) {
add_action('deactivate_' . $plugin_path, array($this, 'payeezy_deactivate'));
add_action('activate_' . $plugin_path, array($this, 'payeezy_activate'));
}

add_action('woocommerce_update_options', array($this, 'testmode_check'), 10, 1);
add_action('testmode_check', array($this, 'testmode_check'));
}

/**
* Checks the test mode status of Payeezy and Click and Pledge gateways.
*
* This function checks if the specified WooCommerce gateways (Payeezy and Click and Pledge)
* are active or inactive and whether their respective plugin files exist. If the conditions
* are met, it calls respective functions to check the test mode status of these gateways.
*/
public function testmode_check()
{
$plugin_path = 'woocommerce-gateway-firstdata/woocommerce-gateway-first-data.php';
if (
(is_plugin_active($plugin_path) || is_plugin_inactive($plugin_path))
&& file_exists(ABSPATH . '/wp-content/plugins/' . $plugin_path)
) {
$this->payeezy_testmode_check();
}

$plugin_path = 'woocommerce-click-pledge-gateway/gateway-clickandpledge.php';
if (
(is_plugin_active($plugin_path) || is_plugin_inactive($plugin_path))
&& file_exists(ABSPATH . '/wp-content/plugins/' . $plugin_path)
) {
$this->clickandpledge_testmode_check();
}
}

public function payeezy_activate()
{
$message = " Production website's Production website's Payeezy Gateway is active!";
$icon = ":heavy_check_mark:";
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
$this->slack_message($message, "Payeezy Gateway Plugin Active", $channel, $icon);
}
public function payeezy_deactivate()
{
$message = "WARNING: Production website's Production website's Payeezy Gateway is in not active!";
$icon = ":warning:";
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
$this->slack_message($message, "Payeezy Gateway Plugin Inactive", $channel, $icon);
}
public function payeezy_testmode_check()
{
// Don't check for WPEngine yet, need to test first
$settings = get_option('woocommerce_first_data_payeezy_gateway_credit_card_settings');
if ($settings['environment'] == 'demo' && get_option('woocommerce_pe_testmode') != 'true') {
update_option('woocommerce_pe_testmode', 'true');
$message = "WARNING: Production website's Payeezy Gateway Environment is set to Demo";
$icon = ":warning:";
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
$this->slack_message($message, "Payeezy Gateway Environment set to Demo", $channel, $icon);
} else if ($settings['environment'] == 'production') {
if (get_option('woocommerce_pe_testmode') == 'true') {
$message = "Production website's Payeezy Gateway Environment is set to Production";
$icon = ":heavy_check_mark:";
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
$this->slack_message($message, "Payeezy Environment set to Production", $channel, $icon);
}
update_option('woocommerce_pe_testmode', 'false');
}

if ($settings['enabled'] == 'no' && get_option('woocommerce_pe_enabled') != 'false') {
update_option('woocommerce_pe_enabled', 'false');
$message = "WARNING: Production website's Payeezy Gateway is not enabled";
$icon = ":warning:";
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
$this->slack_message($message, "Payeezy disabled", $channel, $icon);
} else if ($settings['enabled'] == 'yes') {
if (get_option('woocommerce_pe_enabled') == 'false') {
$message = "Production website's Payeezy Gateway is enabled";
$icon = ":heavy_check_mark:";
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
$this->slack_message($message, "Payeezy Gateway enabled", $channel, $icon);
}
update_option('woocommerce_pe_enabled', 'true');
}
}
public function clickandpledge_activate()
{
$message = " Production website's Click and Pledge Gateway is active!";
$icon = ":heavy_check_mark:";
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
$this->slack_message($message, "Click and Pledge Active", $channel, $icon);
}
public function clickandpledge_deactivate()
{
$message = "WARNING: Production website's Click and Pledge Gateway is in not active!";
$icon = ":warning:";
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
$this->slack_message($message, "Click and Pledge Inactive", $channel, $icon);
}
public function clickandpledge_testmode_check()
{
if (is_wpe()) {
$settings = get_option('woocommerce_clickandpledge_settings');
$p_settings = get_option('woocommerce_clickandpledge_paymentsettings');

if ($p_settings['testmode'] == 'yes') {
update_option('woocommerce_cp_testmode', 'true');
$message = "WARNING: Production website's Click and Pledge Gateway is in Testmode";
$icon = ":warning:";
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
$this->slack_message($message, "Click and Pledge in Testmode", $channel, $icon);
} else {
if (get_option('woocommerce_cp_testmode') == 'true') {
$message = "Production website's Click and Pledge Gateway is in Production";
$icon = ":heavy_check_mark:";
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
$this->slack_message($message, "Click and Pledge in Production", $channel, $icon);
}
update_option('woocommerce_cp_testmode', 'false');
}

if ($p_settings['enabled'] == 'yes') {
if (get_option('woocommerce_cp_enabled') == 'false') {
$message = "Production website's Click and Pledge Gateway is enabled";
$icon = ":heavy_check_mark:";
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
$this->slack_message($message, "Click and Pledge enabled", $channel, $icon);
}
update_option('woocommerce_cp_enabled', 'true');

} else {
update_option('woocommerce_cp_enabled', 'false');
$message = "WARNING: Production website's Click and Pledge Gateway is not enabled";
$icon = ":warning:";
$channel = get_option('wc_settings_tab_slack_woocommerce_channel');
$this->slack_message($message, "Click and Pledge disabled", $channel, $icon);
}

}

}

}
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "burningmantech/woocommerce-slack-notifications",
"description": "Trigger slack notifications when a WooCommerce order status is updated to canceled or completed.",
"type": "wordpress-plugin",
"require": {
"php": "^7.4 || ^8.0"
},
"require-dev": {
}
}
Loading

0 comments on commit 80a4977

Please sign in to comment.