PluginProbe
Tiered Pricing Table for WooCommerce / 2.3.4
Tiered Pricing Table for WooCommerce v2.3.4
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 / Admin / Admin.php

Admin.php in Tiered Pricing Table for WooCommerce 2.3.4, at src/Admin/Admin.php

126 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Admin;
2
3 use TierPricingTable\Admin\ProductManagers\ProductManager;
4 use TierPricingTable\Freemius;
5 use TierPricingTable\Settings\Settings;
6 use TierPricingTable\TierPricingTablePlugin;
7 use Premmerce\SDK\V2\FileManager\FileManager;
8 use TierPricingTable\Admin\ProductManagers\SimpleProductManager;
9 use TierPricingTable\Admin\ProductManagers\VariationProductManager;
10 use TierPricingTable\Admin\Export\Woocommerce as WooCommerceExport;
11 use TierPricingTable\Admin\Import\Woocommerce as WooCommerceImport;
12
13 /**
14 * Class Admin
15 *
16 * @package TierPricingTable\Admin
17 */
18 class Admin {
19
20 /**
21 * @var FileManager
22 */
23 private $fileManager;
24
25 /**
26 * @var Settings
27 */
28 private $settings;
29
30 /**
31 * @var array
32 */
33 private $managers;
34
35 /**
36 * @var Freemius
37 */
38 private $licence;
39
40 /**
41 * Admin constructor.
42 *
43 * Register menu items and handlers
44 *
45 * @param FileManager $fileManager
46 * @param Freemius $licence
47 * @param Settings $settings
48 */
49 public function __construct( FileManager $fileManager, Freemius $licence, Settings $settings ) {
50 $this->fileManager = $fileManager;
51 $this->settings = $settings;
52 $this->licence = $licence;
53
54 $this->initManagers();
55
56 add_action( 'admin_enqueue_scripts', [ $this, 'enqueueAssets' ] );
57
58 if ( get_transient( 'tier_pricing_table_activated' ) ) {
59 add_action( 'admin_notices', [ $this, 'showActivationMessage' ] );
60 }
61
62 if ( $this->licence->isFree() ) {
63
64 $template = 'upgrade-alert.php';
65
66 add_action( 'woocommerce_settings_' . Settings::SETTINGS_PAGE, function () use ( $template ) {
67 $this->fileManager->includeTemplate( 'admin/alerts/' . $template, [
68 'upgradeUrl' => tpt_fs()->get_upgrade_url(),
69 'contactUsUrl' => $this->licence->getContactUsPageUrl()
70 ] );
71
72 $this->fileManager->includeTemplate( 'admin/only-in-premium-script.php' );
73 } );
74 }
75
76 if ( tpt_fs()->is__premium_only() ) {
77 add_action( 'woocommerce_settings_' . Settings::SETTINGS_PAGE, function () {
78 $this->fileManager->includeTemplate( 'admin/alerts/premium-thanking-alert.php', [
79 'accountUrl' => $this->licence->getAccountPageUrl(),
80 'contactUsUrl' => $this->licence->getContactUsPageUrl()
81 ] );
82 } );
83 }
84 }
85
86 /**
87 * Init Managers
88 */
89 public function initManagers() {
90
91 $this->managers = [
92 ProductManager::class => new ProductManager( $this->fileManager, $this->settings,
93 $this->licence ),
94 VariationProductManager::class => new VariationProductManager( $this->fileManager, $this->settings,
95 $this->licence ),
96 WooCommerceExport::class => new WooCommerceExport(),
97 WooCommerceImport::class => new WooCommerceImport()
98 ];
99 }
100
101 /**
102 * Show message about activation plugin and advise next step
103 */
104 public function showActivationMessage() {
105 $link = $this->settings->getLink();
106 $this->fileManager->includeTemplate( 'admin/alerts/activation-alert.php', [ 'link' => $link ] );
107
108 delete_transient( 'tiered_pricing_table_activated' );
109 }
110
111 /**
112 * Register assets on product create/update page
113 *
114 * @param $page
115 */
116 public function enqueueAssets( $page ) {
117 global $post, $page;
118
119 if ( ( isset( $_GET['tab'] ) && $_GET['tab'] == Settings::SETTINGS_PAGE ) || ( ( $page == 'post.php' || $page = 'post-new.php' ) && $post && $post->post_type == 'product' ) ) {
120 wp_enqueue_script( 'tier-pricing-table-admin-js', $this->fileManager->locateAsset( 'admin/main.js' ),
121 'jquery', TierPricingTablePlugin::VERSION );
122 wp_enqueue_style( 'tier-pricing-table-admin-css', $this->fileManager->locateAsset( 'admin/style.css' ),
123 null, TierPricingTablePlugin::VERSION );
124 }
125 }
126 }