PluginProbe
Tiered Pricing Table for WooCommerce / 2.3.3
Tiered Pricing Table for WooCommerce v2.3.3
7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 All 90 releases
tier-pricing-table / src / TierPricingTablePlugin.php

TierPricingTablePlugin.php in Tiered Pricing Table for WooCommerce 2.3.3, at src/TierPricingTablePlugin.php

198 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable;
2
3 use Premmerce\SDK\V2\Notifications\AdminNotifier;
4 use TierPricingTable\Settings\Settings;
5 use Premmerce\SDK\V2\FileManager\FileManager;
6 use TierPricingTable\Admin\Admin;
7 use TierPricingTable\Frontend\Frontend;
8 use TierPricingTable\BackgroundProcessing\Updater\Updater;
9
10 /**
11 * Class TierPricingTablePlugin
12 *
13 * @package TierPricingTable
14 */
15 class TierPricingTablePlugin {
16
17 /**
18 * @var FileManager
19 */
20 private $fileManager;
21
22 /**
23 * @var Settings
24 */
25 private $settings;
26
27 /**
28 * @var AdminNotifier
29 */
30 private $notifier;
31
32 /**
33 * @var Freemius
34 */
35 private $licence;
36
37 /**
38 * @var Integrations\Integrations
39 */
40 private $integrations;
41
42 const VERSION = '2.3.3';
43
44 const DB_VERSION = '2.0';
45
46 /**
47 * TierPricingTablePlugin constructor.
48 *
49 * @param string $mainFile
50 */
51 public function __construct( $mainFile ) {
52 $this->licence = new Freemius( $mainFile );
53 $this->fileManager = new FileManager( $mainFile, 'tier-pricing-table' );
54 $this->settings = new Settings( $this->fileManager );
55 $this->notifier = new AdminNotifier();
56
57 $this->integrations = new Integrations\Integrations();
58
59 add_action( 'init', [ $this, 'loadTextDomain' ], - 999 );
60 add_action( 'admin_init', [ $this, 'checkRequirePlugins' ] );
61
62 add_filter( 'plugin_action_links_' . plugin_basename( $this->fileManager->getMainFile() ),
63 [ $this, 'addPluginAction' ], 10, 4 );
64 }
65
66 /**
67 * Add setting to plugin actions at plugins list
68 *
69 * @param array $actions
70 *
71 * @return array
72 */
73 public function addPluginAction( $actions ) {
74 $actions[] = '<a href="' . $this->settings->getLink() . '">' . __( 'Settings', 'tier-pricing-table' ) . '</a>';
75
76 if ( ! tpt_fs()->is_anonymous() && tpt_fs()->is_installed_on_site() ) {
77 $actions[] = '<a href="' . $this->licence->getAccountPageUrl() . '"><b style="color: green">' . __( 'Account',
78 'tier-pricing-table' ) . '</b></a>';
79 }
80
81 $actions[] = '<a href="' . $this->licence->getContactUsPageUrl() . '"><b style="color: green">' . __( 'Contact Us',
82 'tier-pricing-table' ) . '</b></a>';
83
84 if ( !tpt_fs()->is_premium() ) {
85 $actions[] = '<a href="' . tpt_fs()->get_upgrade_url() . '"><b style="color: red">' . __( 'GO PREMIUM',
86 'tier-pricing-table' ) . '</b></a>';
87 }
88
89 return $actions;
90 }
91
92 /**
93 * Run plugin part
94 */
95 public function run() {
96 $valid = count( $this->validateRequiredPlugins() ) === 0 && $this->licence->isValid();
97 $updater = new Updater();
98
99 if ( $valid && ! $updater->checkForUpdates() ) {
100
101 if ( is_admin() ) {
102 new Admin( $this->fileManager, $this->licence, $this->settings );
103 } else {
104 new Frontend( $this->fileManager, $this->licence, $this->settings );
105 }
106
107 } else {
108 $updater->update();
109 }
110 }
111
112 /**
113 * Load plugin translations
114 */
115 public function loadTextDomain() {
116 $name = $this->fileManager->getPluginName();
117 load_plugin_textdomain( 'tier-pricing-table', false, $name . '/languages/' );
118 }
119
120 /**
121 * Validate required plugins
122 *
123 * @return array
124 */
125 private function validateRequiredPlugins() {
126 $plugins = [];
127
128 if ( ! function_exists( 'is_plugin_active' ) ) {
129 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
130 }
131
132 /**
133 * Check if WooCommerce is active
134 **/
135 if ( ! ( is_plugin_active( 'woocommerce/woocommerce.php' ) || is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) ) {
136 $plugins[] = '<a target="_blank" href="https://wordpress.org/plugins/woocommerce/">WooCommerce</a>';
137 }
138
139 return $plugins;
140 }
141
142 /**
143 * Check required plugins and push notifications
144 */
145 public function checkRequirePlugins() {
146 $message = __( 'The %s plugin requires %s plugin to be active!', 'tier-pricing-table' );
147
148 $plugins = $this->validateRequiredPlugins();
149
150 if ( count( $plugins ) ) {
151 foreach ( $plugins as $plugin ) {
152 $error = sprintf( $message, 'Tiered Pricing Table', $plugin );
153 $this->notifier->push( $error, AdminNotifier::ERROR, false );
154 }
155 }
156 }
157
158 /**
159 * Fired during plugin uninstall
160 */
161 public static function uninstall() {
162 delete_post_meta_by_key( '_price_rules' );
163
164 delete_option( Settings::SETTINGS_PREFIX . 'display' );
165 delete_option( Settings::SETTINGS_PREFIX . 'position_hook' );
166 delete_option( Settings::SETTINGS_PREFIX . 'head_quantity_text' );
167 delete_option( Settings::SETTINGS_PREFIX . 'head_price_text' );
168 delete_option( Settings::SETTINGS_PREFIX . 'display_type' );
169 delete_option( Settings::SETTINGS_PREFIX . 'selected_quantity_color' );
170 delete_option( Settings::SETTINGS_PREFIX . 'table_title' );
171 delete_option( Settings::SETTINGS_PREFIX . 'table_css_class' );
172 delete_option( Settings::SETTINGS_PREFIX . 'tooltip_size' );
173
174 // Premium
175 delete_option( Settings::SETTINGS_PREFIX . 'show_discount_in_cart' );
176 delete_option( Settings::SETTINGS_PREFIX . 'tiered_price_at_catalog' );
177 delete_option( Settings::SETTINGS_PREFIX . 'show_discount_column' );
178 delete_option( Settings::SETTINGS_PREFIX . 'tiered_price_at_catalog_type' );
179 delete_option( Settings::SETTINGS_PREFIX . 'lowest_prefix' );
180 delete_option( Settings::SETTINGS_PREFIX . 'head_discount_text' );
181 delete_option( Settings::SETTINGS_PREFIX . 'clickable_table_rows' );
182 delete_option( Settings::SETTINGS_PREFIX . 'show_total_price' );
183 delete_option( Settings::SETTINGS_PREFIX . 'tiered_price_at_product_page' );
184
185 delete_option( Updater::DB_OPTION );
186 }
187
188 /**
189 * Plugin activation
190 */
191 public function activate() {
192 set_transient( 'tiered_pricing_table_activated', true, 100 );
193 }
194
195 public function deactivate() {
196
197 }
198 }