| 1 |
<?php |
| 2 |
namespace EverCompare\Admin; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
/** |
| 6 |
* Notices handlers class |
| 7 |
*/ |
| 8 |
class Notices { |
| 9 |
|
| 10 |
/** |
| 11 |
* Run the Notices |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
public function notice() { |
| 16 |
$this->all_notices(); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Add Notices |
| 21 |
*/ |
| 22 |
public function all_notices() { |
| 23 |
|
| 24 |
// Notice for WooCommerce |
| 25 |
if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
| 26 |
add_action( 'admin_notices', [ $this, 'admin_notice_missing_woocommerce_plugin' ] ); |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* [is_plugins_active] Check Plugin is Installed or not |
| 34 |
* @param [string] $pl_file_path plugin file path |
| 35 |
* @return boolean true|false |
| 36 |
*/ |
| 37 |
public function is_plugins_active( $pl_file_path = NULL ){ |
| 38 |
$installed_plugins_list = get_plugins(); |
| 39 |
return isset( $installed_plugins_list[$pl_file_path] ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* [admin_notice_missing_woocommerce_plugin] Admin Notice For missing WooCommerce |
| 44 |
* @return [void] |
| 45 |
*/ |
| 46 |
public function admin_notice_missing_woocommerce_plugin(){ |
| 47 |
$woocommerce = 'woocommerce/woocommerce.php'; |
| 48 |
if( $this->is_plugins_active( $woocommerce ) ) { |
| 49 |
if( ! current_user_can( 'activate_plugins' ) ) { |
| 50 |
return; |
| 51 |
} |
| 52 |
$activation_url = wp_nonce_url( 'plugins.php?action=activate&plugin=' . $woocommerce . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $woocommerce ); |
| 53 |
/* |
| 54 |
* translators: %1$s: strong tag start |
| 55 |
* translators: %2$s: strong tag end |
| 56 |
*/ |
| 57 |
$message = sprintf( __( '%1$sEver Compare%2$s requires %1$s"WooCommerce"%2$s plugin to be active. Please activate WooCommerce to continue.', 'ever-compare' ), '<strong>', '</strong>'); |
| 58 |
$button_text = __( 'Activate WooCommerce', 'ever-compare' ); |
| 59 |
} else { |
| 60 |
if( ! current_user_can( 'activate_plugins' ) ) { |
| 61 |
return; |
| 62 |
} |
| 63 |
$activation_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' ); |
| 64 |
/* |
| 65 |
* translators: %1$s: strong tag start |
| 66 |
* translators: %2$s: strong tag end |
| 67 |
*/ |
| 68 |
$message = sprintf( __( '%1$sEver Compare%2$s requires %1$s"WooCommerce"%2$s plugin to be installed and activated. Please install WooCommerce to continue.', 'ever-compare' ), '<strong>', '</strong>' ); |
| 69 |
$button_text = __( 'Install WooCommerce', 'ever-compare' ); |
| 70 |
} |
| 71 |
$button = '<p><a href="' . $activation_url . '" class="button-primary">' . $button_text . '</a></p>'; |
| 72 |
printf( '<div class="error"><p>%1$s</p>%2$s</div>', wp_kses_post($message) , wp_kses_post($button) ); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
} |