PluginProbe
Tiered Pricing Table for WooCommerce / 2.1.2
Tiered Pricing Table for WooCommerce v2.1.2
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.1.2, at src/TierPricingTablePlugin.php

187 lines 4.9 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 const VERSION = '2.1.2';
38
39 const DB_VERSION = '2.0';
40
41 /**
42 * TierPricingTablePlugin constructor.
43 *
44 * @param string $mainFile
45 */
46 public function __construct( $mainFile ) {
47 $this->licence = new Freemius( $mainFile );
48 $this->fileManager = new FileManager( $mainFile, 'tier-pricing-table' );
49 $this->settings = new Settings( $this->fileManager );
50 $this->notifier = new AdminNotifier();
51
52 add_action( 'init', [ $this, 'loadTextDomain' ], - 999 );
53 add_action( 'admin_init', [ $this, 'checkRequirePlugins' ] );
54
55 add_filter( 'plugin_action_links_' . plugin_basename( $this->fileManager->getMainFile() ),
56 [ $this, 'addPluginAction' ], 10, 4 );
57
58 add_action('init', function(){
59
60 });
61 }
62
63 /**
64 * Add setting to plugin actions at plugins list
65 *
66 * @param array $actions
67 *
68 * @return array
69 */
70 public function addPluginAction( $actions ) {
71 $actions[] = '<a href="' . $this->settings->getLink() . '">' . __( 'Settings', 'tier-pricing-table' ) . '</a>';
72
73 if ( ! tpt_fs()->is_anonymous() && tpt_fs()->is_installed_on_site() ) {
74 $actions[] = '<a href="' . $this->licence->getAccountPageUrl() . '"><b style="color: green">' . __( 'Account',
75 'tier-pricing-table' ) . '</b></a>';
76 }
77
78 $actions[] = '<a href="' . $this->licence->getContactUsPageUrl() . '"><b style="color: green">' . __( 'Contact Us',
79 'tier-pricing-table' ) . '</b></a>';
80
81 return $actions;
82 }
83
84 /**
85 * Run plugin part
86 */
87 public function run() {
88 $valid = count( $this->validateRequiredPlugins() ) === 0 && $this->licence->isValid();
89 $updater = new Updater();
90
91 if ( $valid && ! $updater->checkForUpdates() ) {
92
93 if ( is_admin() ) {
94
95 new Admin( $this->fileManager, $this->licence, $this->settings );
96 } else {
97 new Frontend( $this->fileManager, $this->licence, $this->settings );
98 }
99
100 } else {
101 $updater->update();
102 }
103 }
104
105 /**
106 * Load plugin translations
107 */
108 public function loadTextDomain() {
109 $name = $this->fileManager->getPluginName();
110 load_plugin_textdomain( 'tier-pricing-table', false, $name . '/languages/' );
111 }
112
113 /**
114 * Validate required plugins
115 *
116 * @return array
117 */
118 private function validateRequiredPlugins() {
119 $plugins = [];
120
121 if ( ! function_exists( 'is_plugin_active' ) ) {
122 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
123 }
124
125 /**
126 * Check if WooCommerce is active
127 **/
128 if ( ! ( is_plugin_active( 'woocommerce/woocommerce.php' ) || is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) ) {
129 $plugins[] = '<a target="_blank" href="https://wordpress.org/plugins/woocommerce/">WooCommerce</a>';
130 }
131
132 return $plugins;
133 }
134
135 /**
136 * Check required plugins and push notifications
137 */
138 public function checkRequirePlugins() {
139 $message = __( 'The %s plugin requires %s plugin to be active!', 'tier-pricing-table' );
140
141 $plugins = $this->validateRequiredPlugins();
142
143 if ( count( $plugins ) ) {
144 foreach ( $plugins as $plugin ) {
145 $error = sprintf( $message, 'Tiered Pricing Table', $plugin );
146 $this->notifier->push( $error, AdminNotifier::ERROR, false );
147 }
148 }
149 }
150
151 /**
152 * Fired during plugin uninstall
153 */
154 public static function uninstall() {
155 delete_post_meta_by_key( '_price_rules' );
156
157 delete_option( Settings::SETTINGS_PREFIX . 'display' );
158 delete_option( Settings::SETTINGS_PREFIX . 'position_hook' );
159 delete_option( Settings::SETTINGS_PREFIX . 'head_quantity_text' );
160 delete_option( Settings::SETTINGS_PREFIX . 'head_price_text' );
161 delete_option( Settings::SETTINGS_PREFIX . 'display_type' );
162 delete_option( Settings::SETTINGS_PREFIX . 'selected_quantity_color' );
163 delete_option( Settings::SETTINGS_PREFIX . 'table_title' );
164 delete_option( Settings::SETTINGS_PREFIX . 'table_css_class' );
165 delete_option( Settings::SETTINGS_PREFIX . 'tooltip_size' );
166
167 delete_option( Settings::SETTINGS_PREFIX . 'show_discount_in_cart' );
168 delete_option( Settings::SETTINGS_PREFIX . 'tiered_price_at_catalog' );
169 delete_option( Settings::SETTINGS_PREFIX . 'show_discount_column' );
170 delete_option( Settings::SETTINGS_PREFIX . 'tiered_price_at_catalog_type' );
171 delete_option( Settings::SETTINGS_PREFIX . 'lowest_prefix' );
172 delete_option( Settings::SETTINGS_PREFIX . 'head_discount_text' );
173
174 delete_option(Updater::DB_OPTION);
175 }
176
177 /**
178 * Plugin activation
179 */
180 public function activate() {
181 set_transient( 'tiered_pricing_table_activated', true, 100 );
182 }
183
184 public function deactivate() {
185
186 }
187 }