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 / Admin / Admin.php

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

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