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