1
0
Fork 0
mirror of synced 2025-04-06 07:13:33 +03:00

fix & improvement for woocommerce missing notice

This commit is contained in:
Pavel 2020-02-13 12:12:16 +03:00
parent 4d5b38bb54
commit 0a62cbd15c
2 changed files with 77 additions and 1 deletions

View file

@ -53,6 +53,12 @@ class WC_Retailcrm_Plugin {
}
public function activate() {
if (!class_exists( 'WC_Integration' ) ) {
add_action('admin_notices', array(new WC_Integration_Retailcrm(), 'woocommerce_missing_notice'));
return;
}
if (!class_exists('WC_Retailcrm_Icml')) {
require_once (dirname(__FILE__) . '/class-wc-retailcrm-icml.php');
}

View file

@ -21,6 +21,8 @@ if (!class_exists( 'WC_Integration_Retailcrm')) :
* Class WC_Integration_Retailcrm
*/
class WC_Integration_Retailcrm {
const WOOCOMMERCE_SLUG = 'woocommerce';
const WOOCOMMERCE_PLUGIN_PATH = 'woocommerce/woocommerce.php';
private static $instance;
@ -56,7 +58,30 @@ if (!class_exists( 'WC_Integration_Retailcrm')) :
}
public function woocommerce_missing_notice() {
echo '<div class="error"><p>Woocommerce is not installed</p></div>';
if (static::isWooCommerceInstalled()) {
if (!is_plugin_active(static::WOOCOMMERCE_PLUGIN_PATH)) {
echo '
<div class="error">
<p>
Activate WooCommerce in order to enable retailCRM integration!
<a href="' . wp_nonce_url(admin_url('plugins.php')) . '" aria-label="Activate WooCommerce">
Click here to open plugins manager
</a>
</p>
</div>
';
}
} else {
echo '
<div class="error">
<p>
<a href="'
. static::generatePluginInstallationUrl(static::WOOCOMMERCE_SLUG)
. '" aria-label="Install WooCommerce">Install WooCommerce</a> in order to enable retailCRM integration!
</p>
</div>
';
}
}
public function load_plugin_textdomain() {
@ -74,6 +99,51 @@ if (!class_exists( 'WC_Integration_Retailcrm')) :
$integrations[] = 'WC_Retailcrm_Base';
return $integrations;
}
/**
* Returns true if WooCommerce was found in plugin cache
*
* @return bool
*/
private function isWooCommerceInstalled()
{
$plugins = wp_cache_get( 'plugins', 'plugins' );
if (!$plugins) {
$plugins = get_plugins();
} elseif (isset($plugins[''])) {
$plugins = $plugins[''];
}
if (!isset($plugins[static::WOOCOMMERCE_PLUGIN_PATH])) {
return false;
}
return true;
}
/**
* Generate plugin installation url
*
* @param $pluginSlug
*
* @return string
*/
private function generatePluginInstallationUrl($pluginSlug)
{
$action = 'install-plugin';
return wp_nonce_url(
add_query_arg(
array(
'action' => $action,
'plugin' => $pluginSlug
),
admin_url( 'update.php' )
),
$action.'_'.$pluginSlug
);
}
}
if (!class_exists('WC_Retailcrm_Plugin')) {