first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
{
"name": "wpdesk\/wp-wpdesk-fs-compatibility",
"authors": [
{
"name": "Sebastian",
"email": "sebastian.pisula@flexibleshipping.com"
}
],
"require": {
"php": ">=5.6",
"wpdesk\/wp-notice": "^3.1.3",
"psr\/log": "^1.1",
"wpdesk\/wp-builder": "^1.4|^2"
},
"require-dev": {
"phpunit\/phpunit": "<7",
"mockery\/mockery": "^1.2",
"10up\/wp_mock": "^0.3"
},
"autoload": {
"psr-4": {
"FSVendor\\WPDesk\\FS\\Compatibility\\": "src\/"
}
},
"autoload-dev": {},
"extra": {
"text-domain": "wp-wpdesk-fs-compatibility",
"translations-folder": "lang",
"po-files": {
"pl_PL": "pl_PL.po"
}
},
"scripts": {
"phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never",
"phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage",
"phpunit-integration": "phpunit --configuration phpunit-integration.xml --coverage-text --colors=never",
"phpunit-integration-fast": "phpunit --configuration phpunit-integration.xml --no-coverage"
}
}

View File

@@ -0,0 +1,116 @@
<?php
/**
* Block Settings
*
* @package WPDesk\FS\Compatibility
*/
namespace FSVendor\WPDesk\FS\Compatibility;
use WC_Shipping_Zones;
use FSVendor\WPDesk_Flexible_Shipping;
/**
* Can prevent Flexible Shipping settings saving.
*/
class BlockSettings
{
/**
* @var PluginCompatibilityChecker .
*/
private $plugin_compatibility_checker;
/**
* Notice constructor.
*
* @param PluginCompatibilityChecker $plugin_compatibility_checker .
*/
public function __construct(\FSVendor\WPDesk\FS\Compatibility\PluginCompatibilityChecker $plugin_compatibility_checker)
{
$this->plugin_compatibility_checker = $plugin_compatibility_checker;
}
/**
* Add hooks.
*/
public function hooks()
{
\add_action('admin_init', array($this, 'block_save_settings'));
\add_action('flexible-shipping/method-rules-settings/table/before', array($this, 'add_flexible_shipping_method_message'));
\add_action('flexible_shipping_method_script', array($this, 'add_flexible_shipping_method_message'));
}
/**
* Action when setting are saving.
*/
public function block_save_settings()
{
if (!isset($_POST['save'], $_POST['settings_saving_block'])) {
return;
}
$tab = \filter_input(\INPUT_GET, 'tab');
$page = \filter_input(\INPUT_GET, 'page');
if ('wc-settings' !== $page || 'shipping' !== $tab) {
return;
}
$_wpnonce = \filter_input(\INPUT_POST, '_wpnonce');
if (!\wp_verify_nonce(\wp_unslash($_wpnonce), 'woocommerce-settings')) {
return;
}
$method_title = \filter_input(\INPUT_POST, 'woocommerce_flexible_shipping_method_title');
$instance_id = \absint(\wp_unslash(\filter_input(\INPUT_GET, 'instance_id')));
if (!$method_title || !$instance_id) {
return;
}
$shipping_method = \WC_Shipping_Zones::get_shipping_method($instance_id);
if (!$shipping_method) {
return;
}
\wp_die($this->get_general_message(), '', array('link_url' => $this->get_plugin_update_url(), 'link_text' => $this->get_plugin_update_label(), 'back_link' => \true));
// WPCS: XSS OK.
}
/**
* Add scripts for FS method.
*/
public function add_flexible_shipping_method_message()
{
$status = (bool) \apply_filters('plugin_compatibility_checker/js_added', \false);
if ($status) {
return;
}
$action = \filter_input(\INPUT_GET, 'action');
if (!$action) {
return;
}
\add_filter('plugin_compatibility_checker/js_added', '__return_true');
$message = $this->get_message_for_settings();
include \wp_normalize_path(__DIR__ . '/views/html-update-settings-alert.php');
}
/**
* Message for incompatible plugins.
*
* @return string
*/
private function get_message_for_settings()
{
return \sprintf('%s %s', $this->get_general_message(), \sprintf('%s%s%s', \sprintf('<a target="_blank" href="%s">', $this->get_plugin_update_url()), $this->get_plugin_update_label(), '</a>'));
}
/**
* @return string
*/
private function get_general_message()
{
$plugins = \implode(', ', $this->plugin_compatibility_checker->get_list_of_incompatible_plugins());
return \sprintf(\__('In order to prevent any further issues with the plugin configuration or its proper functioning, before saving the changes please update the following: %s.', 'flexible-shipping'), \sprintf('<strong>%s</strong>', $plugins));
}
/**
* @return string
*/
private function get_plugin_update_label()
{
return \__('Go to the plugins list &rarr;', 'flexible-shipping');
}
/**
* @return string
*/
private function get_plugin_update_url()
{
return \add_query_arg('s', 'Flexible Shipping', \admin_url('plugins.php'));
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* Notice
*
* @package WPDesk\FS\Compatibility
*/
namespace FSVendor\WPDesk\FS\Compatibility;
/**
* Can display notice about incompatible plugins.
*/
class Notice
{
/**
* @var PluginCompatibilityChecker .
*/
private $plugin_compatibility_checker;
/**
* Notice constructor.
*
* @param PluginCompatibilityChecker $plugin_compatibility_checker .
*/
public function __construct(\FSVendor\WPDesk\FS\Compatibility\PluginCompatibilityChecker $plugin_compatibility_checker)
{
$this->plugin_compatibility_checker = $plugin_compatibility_checker;
}
/**
* Add hooks.
*/
public function hooks()
{
\add_action('admin_notices', array($this, 'admin_notices'));
}
/**
* Display notices in admin.
*/
public function admin_notices()
{
$status = (bool) \apply_filters('plugin_compatibility_checker/notice_added', \false);
if ($status) {
return;
}
\add_filter('plugin_compatibility_checker/notice_added', '__return_true');
$checker = $this->plugin_compatibility_checker;
$additional_info = ' ' . \sprintf(\__('If the WordPress updater hasn\'t informed you about the newer versions available, please %sfollow these instructions &rarr;%s', 'flexible-shipping'), \sprintf('<a href="%s" target="_blank">', \__('https://octol.io/fs-2-docs', 'flexible-shipping')), '</a>');
if (!$checker->is_fs_compatible()) {
if ($checker->is_active_fs_pro() && $checker->is_fs_pro_compatible() && $checker->is_active_fs_loc() && $checker->is_fs_loc_compatible()) {
new \FSVendor\WPDesk\Notice\Notice(\sprintf(\__('%sFlexible Shipping%s plugin you are currently using is not compatible with the installed version of Flexible Shipping PRO and Flexible Shipping Locations. Please update the %sFlexible Shipping%s plugin to %s version or newer.', 'flexible-shipping'), '<strong>', '</strong>', '<strong>', '</strong>', $checker->fs->get_required_version()) . $additional_info, 'error');
} elseif ($checker->is_active_fs_pro() && $checker->is_fs_pro_compatible()) {
new \FSVendor\WPDesk\Notice\Notice(\sprintf(\__('%sFlexible Shipping%s plugin you are currently using is not compatible with the installed version of Flexible Shipping PRO. Please update the %sFlexible Shipping%s plugin to %s version or newer.', 'flexible-shipping'), '<strong>', '</strong>', '<strong>', '</strong>', $checker->fs->get_required_version()) . $additional_info, 'error');
} elseif ($checker->is_active_fs_loc() && $checker->is_fs_loc_compatible()) {
new \FSVendor\WPDesk\Notice\Notice(\sprintf(\__('%sFlexible Shipping%s plugin you are currently using is not compatible with the installed version of Flexible Shipping Locations. Please update the %sFlexible Shipping%s plugin to %s version or newer.', 'flexible-shipping'), '<strong>', '</strong>', '<strong>', '</strong>', $checker->fs->get_required_version()) . $additional_info, 'error');
}
} else {
if (!$checker->is_fs_pro_compatible()) {
new \FSVendor\WPDesk\Notice\Notice(\sprintf(\__('%sFlexible Shipping PRO%s plugin you are currently using is not compatible with the installed version of Flexible Shipping free. Please update the %sFlexible Shipping PRO%s plugin to %s version or newer.', 'flexible-shipping'), '<strong>', '</strong>', '<strong>', '</strong>', $checker->fs_pro->get_required_version()) . $additional_info, 'error');
}
if (!$checker->is_fs_loc_compatible()) {
new \FSVendor\WPDesk\Notice\Notice(\sprintf(\__('%sFlexible Shipping Locations%s plugin you are currently using is not compatible with the installed version of Flexible Shipping free. Please update the %sFlexible Shipping Locations%s plugin to %s version or newer.', 'flexible-shipping'), '<strong>', '</strong>', '<strong>', '</strong>', $checker->fs_loc->get_required_version()) . $additional_info, 'error');
}
}
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* Class Plugin Compatibility
*
* @package WPDesk\FS\Compatibility
*/
namespace FSVendor\WPDesk\FS\Compatibility;
use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Class Plugin Compatibility
*/
class PluginCompatibility implements \FSVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
/**
* PluginCompatibility constructor.
*/
public function hooks()
{
\add_action('plugins_loaded', array($this, 'init_plugin_checker'));
}
/**
* Init plugin checker.
*/
public function init_plugin_checker()
{
if (!\is_admin()) {
return;
}
$plugin_compatibility_checker = new \FSVendor\WPDesk\FS\Compatibility\PluginCompatibilityChecker();
if (!$plugin_compatibility_checker->are_plugins_compatible()) {
$notice = new \FSVendor\WPDesk\FS\Compatibility\Notice($plugin_compatibility_checker);
$notice->hooks();
$block_settings = new \FSVendor\WPDesk\FS\Compatibility\BlockSettings($plugin_compatibility_checker);
$block_settings->hooks();
}
}
}

View File

@@ -0,0 +1,116 @@
<?php
/**
* Plugin Compatibility Checker
*
* @package WPDesk\FS\TableRate
*/
namespace FSVendor\WPDesk\FS\Compatibility;
/**
* Class PluginCompatibilityChecker
*
* @package WPDesk\FS\TableRate
*/
class PluginCompatibilityChecker
{
/**
* @var PluginDetails .
*/
public $fs;
/**
* @var PluginDetails .
*/
public $fs_pro;
/**
* @var PluginDetails .
*/
public $fs_loc;
/**
* PluginCompatibilityChecker constructor.
*/
public function __construct()
{
$this->fs = new \FSVendor\WPDesk\FS\Compatibility\PluginDetails('flexible-shipping/flexible-shipping.php', 'FLEXIBLE_SHIPPING_VERSION', '4.0.0');
$this->fs_pro = new \FSVendor\WPDesk\FS\Compatibility\PluginDetails('flexible-shipping-pro/flexible-shipping-pro.php', 'FLEXIBLE_SHIPPING_PRO_VERSION', '2.0.0');
$this->fs_loc = new \FSVendor\WPDesk\FS\Compatibility\PluginDetails('flexible-shipping-locations/flexible-shipping-locations.php', 'FLEXIBLE_SHIPPING_LOCATIONS_VERSION', '2.0.0');
}
/**
* @return bool
*/
public function is_active_fs()
{
return $this->fs->is_active();
}
/**
* @return bool
*/
public function is_active_fs_pro()
{
return $this->fs_pro->is_active();
}
/**
* @return bool
*/
public function is_active_fs_loc()
{
return $this->fs_loc->is_active();
}
/**
* @return bool
*/
public function are_plugins_compatible()
{
return $this->is_fs_compatible() && $this->is_fs_pro_compatible() && $this->is_fs_loc_compatible();
}
/**
* @return bool
*/
public function is_fs_compatible()
{
return $this->check_plugin($this->fs);
}
/**
* @return bool
*/
public function is_fs_pro_compatible()
{
return $this->check_plugin($this->fs_pro);
}
/**
* @return bool
*/
public function is_fs_loc_compatible()
{
return $this->check_plugin($this->fs_loc);
}
/**
* @return array
*/
public function get_list_of_incompatible_plugins()
{
$plugins_list = [];
if (!$this->is_fs_compatible()) {
$plugins_list[] = \__('Flexible Shipping', 'flexible-shipping');
}
if (!$this->is_fs_pro_compatible()) {
$plugins_list[] = \__('Flexible Shipping PRO', 'flexible-shipping');
}
if (!$this->is_fs_loc_compatible()) {
$plugins_list[] = \__('Flexible Shipping Locations', 'flexible-shipping');
}
return $plugins_list;
}
/**
* @param PluginDetails $plugin .
*
* @return bool
*/
private function check_plugin($plugin)
{
if (!$plugin->is_active()) {
return \true;
}
return $plugin->is_compatible();
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* Class Plugin Details
*
* @package WPDesk\FS\Compatibility
*/
namespace FSVendor\WPDesk\FS\Compatibility;
/**
* Class PluginDetails
*
* @package WPDesk\FS\Compatibility
*/
class PluginDetails
{
/**
* @var string .
*/
private $plugin_file;
/**
* @var string|null .
*/
private $version_constant_name;
/**
* @var string .
*/
private $required_version;
/**
* PluginChecker constructor.
*
* @param string $plugin_file .
* @param string $version_constant_name .
* @param string $required_version .
*/
public function __construct($plugin_file, $version_constant_name, $required_version)
{
$this->plugin_file = $plugin_file;
$this->version_constant_name = $version_constant_name;
$this->required_version = $required_version;
}
/**
* @return bool
*/
public function is_active()
{
return $this->is_plugin_activate($this->plugin_file);
}
/**
* @return string
*/
public function get_version()
{
return \defined($this->version_constant_name) ? \constant($this->version_constant_name) : '0.0.0';
}
/**
* @return string
*/
public function get_required_version()
{
return $this->required_version;
}
/**
* @return bool
*/
public function is_compatible()
{
return $this->compare_version($this->required_version, '>=');
}
/**
* @param string $version .
* @param string $operator .
*
* @return bool
*/
private function compare_version($version, $operator = null)
{
return \version_compare($this->get_version(), $version, $operator);
}
/**
* @param string $plugin_file .
*
* @return bool
*/
private function is_plugin_activate($plugin_file)
{
$active_plugins = (array) \get_option('active_plugins', []);
if (\is_multisite()) {
$active_plugins = \array_merge($active_plugins, \get_site_option('active_sitewide_plugins', []));
}
return \in_array($plugin_file, $active_plugins) || \array_key_exists($plugin_file, $active_plugins);
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace FSVendor;
/** @var string $message */
?>
<p id="woocommerce_flexible_shipping_compatibility_message"
style="color: red;margin-bottom: 20px;"><?php
echo \wp_kses_post($message);
?></p>
<input type="hidden" name="settings_saving_block" value="1"/>
<script type="text/javascript">
document.addEventListener( "DOMContentLoaded", function ( event ) {
document.querySelector( '#mainform .woocommerce-save-button' ).disabled = true;
var table_container = jQuery( '#woocommerce_flexible_shipping_method_rules' );
var message_container = jQuery( '#woocommerce_flexible_shipping_compatibility_message' );
if ( table_container.length ) {
message_container.insertBefore( table_container );
}
} );
</script><?php