PluginProbe ʕ •ᴥ•ʔ
Conditional Logic for Woo Product Add-ons / 2.1.6
Conditional Logic for Woo Product Add-ons v2.1.6
trunk 1.0.0 1.1.0 1.2.0 1.2.1 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.2.0 2.2.1 2.2.2 2.2.3
conditional-logic-for-woo-product-add-ons / src / AddonsConditionsPlugin.php
conditional-logic-for-woo-product-add-ons / src Last commit date
Admin 1 year ago Core 1 year ago Frontend 1 year ago AddonsConditionsPlugin.php 1 year ago SanitizeManager.php 1 year ago Schema.php 1 year ago
AddonsConditionsPlugin.php
150 lines
1 <?php namespace MeowCrew\AddonsConditions;
2
3 use Automattic\WooCommerce\Utilities\FeaturesUtil;
4 use Exception;
5 use MeowCrew\AddonsConditions\Core\AdminNotifier;
6 use MeowCrew\AddonsConditions\Core\FileManager;
7 use MeowCrew\AddonsConditions\Core\ServiceContainerTrait;
8 use MeowCrew\AddonsConditions\Admin\Admin;
9 use MeowCrew\AddonsConditions\Frontend\Frontend;
10
11 /**
12 * Class AddonsConditionsPlugin
13 *
14 * @package MeowCrew\AddonsConditions
15 */
16 class AddonsConditionsPlugin {
17
18 use ServiceContainerTrait;
19
20 const VERSION = '2.1.6';
21
22 /**
23 * AddonsConditionsPlugin constructor.
24 *
25 * @param string $mainFile
26 */
27 public function __construct( $mainFile ) {
28 FileManager::init( $mainFile, 'conditional-logic-for-product-addons' );
29
30 add_action( 'before_woocommerce_init', function () use ( $mainFile ) {
31 if ( class_exists( FeaturesUtil::class ) ) {
32 FeaturesUtil::declare_compatibility( 'custom_order_tables', $mainFile, true );
33 }
34
35 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
36 FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', $mainFile, true );
37 }
38 } );
39 }
40
41 /**
42 * Run plugin part
43 *
44 * @throws Exception
45 */
46 public function run() {
47 $this->getContainer()->add( 'fileManager', FileManager::getInstance() );
48 $this->getContainer()->add( 'adminNotifier', new AdminNotifier() );
49
50 if ( $this->checkRequirements() ) {
51
52 $this->getContainer()->add( 'admin.service', new Admin() );
53 $this->getContainer()->add( 'frontend.service', new Frontend() );
54
55 add_action( 'plugins_loaded', array( $this, 'loadTextDomain' ) );
56 add_filter( 'plugin_action_links_' . plugin_basename( $this->getContainer()->getFileManager()->getMainFile() ),
57 array( $this, 'addPluginAction' ), 10, 4 );
58 }
59
60 }
61
62 /**
63 * Load plugin translations
64 */
65 public function loadTextDomain() {
66 $name = $this->getContainer()->getFileManager()->getPluginName();
67 load_plugin_textdomain( 'conditional-logic-for-product-addons', false, $name . '/languages/' );
68 }
69
70 public function checkRequirements() {
71 /* translators: %s = required plugin */
72 $message = __( 'Conditions for Product Add-ons requires %s plugin to be active!',
73 'conditional-logic-for-product-addons' );
74
75 $plugins = $this->getRequiredPluginsToBeActive();
76
77 if ( count( $plugins ) ) {
78
79 foreach ( $plugins as $plugin ) {
80 $error = sprintf( $message, $plugin );
81 $this->getContainer()->getAdminNotifier()->push( $error, AdminNotifier::ERROR, false );
82 }
83
84 return false;
85 }
86
87 return true;
88 }
89
90 /**
91 * Add setting to plugin actions at plugins list
92 *
93 * @param array $actions
94 *
95 * @return array
96 */
97 public function addPluginAction( $actions ) {
98
99 $actions[] = '<a target="_blank" href="' . self::getDocumentationURL() . '">' . __( 'Documentation',
100 'tier-pricing-table' ) . '</a>';
101
102 if ( ! clfwpao_fs()->is_anonymous() && clfwpao_fs()->is_installed_on_site() ) {
103 $actions[] = '<a href="' . self::getAccountPageURL() . '"><b style="color: green">' . __( 'Account',
104 'tier-pricing-table' ) . '</b></a>';
105 }
106
107 $actions[] = '<a href="' . self::getContactUsURL() . '"><b style="color: green">' . __( 'Contact Us',
108 'tier-pricing-table' ) . '</b></a>';
109
110 if ( ! clfwpao_fs()->is_premium() ) {
111 $actions[] = '<a href="' . ( clfwpao_fs()->is_activation_mode() ? clfwpao_fs()->get_activation_url() : clfwpao_fs()->get_upgrade_url() ) . '"><b style="color: red">' . __( 'Go Premium',
112 'tier-pricing-table' ) . '</b></a>';
113 }
114
115 return $actions;
116 }
117
118 public function getRequiredPluginsToBeActive() {
119
120 $plugins = array();
121
122 if ( ! function_exists( 'is_plugin_active' ) ) {
123 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
124 }
125
126 if ( ! ( is_plugin_active( 'woocommerce/woocommerce.php' ) || is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) ) {
127 $plugins[] = 'WooCommerce';
128 }
129
130 if ( ! ( is_plugin_active( 'woocommerce-product-addons/woocommerce-product-addons.php' ) || is_plugin_active_for_network( 'woocommerce-product-addons/woocommerce-product-addons.php' ) ) ) {
131 $plugins[] = 'WooCommerce Product Add-ons';
132 }
133
134 return $plugins;
135 }
136
137
138 public static function getDocumentationURL() {
139 return 'https://meow-crew.com/documentation/conditional-logic-for-woocommerce-product-add-ons-documentation ';
140 }
141
142 public static function getContactUsURL() {
143 return admin_url( 'admin.php?page=clfwpao-contact-us' );
144 }
145
146 public static function getAccountPageURL() {
147 return admin_url( 'admin.php?page=clfwpao-account' );
148 }
149 }
150