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