PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
8.0.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 All 91 releases
tier-pricing-table / src / Settings / Sections / PluginPairingSectionAbstract.php

PluginPairingSectionAbstract.php in Tiered Pricing Table for WooCommerce 8.0.2, at src/Settings/Sections/PluginPairingSectionAbstract.php

253 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Settings\Sections;
2
3 use TierPricingTable\Core\ServiceContainerTrait;
4 use TierPricingTable\Settings\Settings;
5
6 /**
7 * Base for "pairing" settings sections (Multicurrency, Product Addons, …): informational tabs that
8 * show which third-party plugin of the kind is detected, the state of its Tiered Pricing
9 * integration (status here — the toggle stays on the Integrations page), and recommend the
10 * U2Code plugin of the same kind. Four states: none detected / competitor detected /
11 * U2Code plugin active / both active (conflict).
12 */
13 abstract class PluginPairingSectionAbstract extends SectionAbstract {
14
15 use ServiceContainerTrait;
16
17 /**
18 * @return array<string, array{name: string, active: bool}> Integration slug => plugin.
19 */
20 abstract public function getSupportedPlugins(): array;
21
22 abstract public function isOwnPluginActive(): bool;
23
24 abstract public function getOwnPluginName(): string;
25
26 /**
27 * Asset path of the plugin icon, relative to the assets directory.
28 */
29 abstract public function getOwnPluginIconAsset(): string;
30
31 /**
32 * Asset path of the plugin's wp.org banner (772×250), relative to the assets directory.
33 */
34 abstract public function getOwnPluginBannerAsset(): string;
35
36 /**
37 * @return array<int, string>
38 */
39 abstract public function getOwnPluginPills(): array;
40
41 abstract public function getOwnPluginWporgURL(): string;
42
43 abstract public function getOwnPluginSiteURL(): string;
44
45 /**
46 * utm_campaign prefix, e.g. 'multicurrency' → 'multicurrency-tab' / 'multicurrency-switch'.
47 */
48 abstract public function getUtmCampaignBase(): string;
49
50 abstract public function getIntroHeading(): string;
51
52 abstract public function getIntroText(): string;
53
54 abstract public function getPromoText(): string;
55
56 abstract public function getPairedBannerText(): string;
57
58 abstract public function getIntegrationEnabledText(): string;
59
60 abstract public function getIntegrationDisabledText(): string;
61
62 /**
63 * @param string $competitorNames Human-readable list of the detected plugins.
64 */
65 abstract public function getConflictText( string $competitorNames ): string;
66
67 public function getConflictBannerClass(): string {
68 return 'tpt-pairing__banner--danger';
69 }
70
71 public function getFieldType(): string {
72 return 'tiered-pricing_' . $this->getSlug() . '-ui';
73 }
74
75 public function __construct() {
76 add_action( 'woocommerce_admin_field_' . $this->getFieldType(), array( $this, 'renderUI' ) );
77 }
78
79 public function getSettings(): array {
80
81 // Pairing sections are informational — there is nothing to save.
82 $GLOBALS['hide_save_button'] = true;
83
84 return array(
85 array(
86 'type' => $this->getFieldType(),
87 ),
88 );
89 }
90
91 /**
92 * @return array<string, array{name: string, active: bool}> Active competitor plugins only.
93 */
94 public function getDetectedCompetitors(): array {
95 return array_filter( $this->getSupportedPlugins(), function ( $plugin ) {
96 return $plugin['active'];
97 } );
98 }
99
100 protected function isIntegrationEnabled( string $slug ): bool {
101 return get_option( Settings::SETTINGS_PREFIX . '_integration_' . $slug, 'yes' ) === 'yes';
102 }
103
104 protected function getIntegrationsPageURL(): string {
105 return admin_url( 'admin.php?page=wc-settings&tab=' . Settings::SETTINGS_PAGE . '&section=integrations' );
106 }
107
108 public function renderUI() {
109
110 $competitors = $this->getDetectedCompetitors();
111 $ownActive = $this->isOwnPluginActive();
112 ?>
113 <div class="tpt-pairing">
114
115 <?php if ( $ownActive && $competitors ) : ?>
116
117 <div class="tpt-pairing__banner <?php echo esc_attr( $this->getConflictBannerClass() ); ?>">
118 <?php echo wp_kses_post( $this->getConflictText( implode( ', ', wp_list_pluck( $competitors, 'name' ) ) ) ); ?>
119 </div>
120
121 <?php elseif ( $ownActive ) : ?>
122
123 <div class="tpt-pairing__banner tpt-pairing__banner--ok">
124 <?php echo wp_kses_post( $this->getPairedBannerText() ); ?>
125 </div>
126
127 <p>
128 <a href="<?php echo esc_url( $this->getIntegrationsPageURL() ); ?>">
129 <?php esc_html_e( 'Manage integrations', 'tier-pricing-table' ); ?> &rarr;
130 </a>
131 </p>
132
133 <?php elseif ( $competitors ) : ?>
134
135 <?php foreach ( $competitors as $slug => $competitor ) : ?>
136 <?php $enabled = $this->isIntegrationEnabled( $slug ); ?>
137 <div class="tpt-pairing__banner <?php echo $enabled ? 'tpt-pairing__banner--ok' : 'tpt-pairing__banner--warning'; ?>">
138 <strong>
139 <?php
140 printf(
141 /* translators: %s: detected plugin name */
142 esc_html__( '%s detected.', 'tier-pricing-table' ),
143 esc_html( $competitor['name'] )
144 );
145 ?>
146 </strong>
147
148 <?php echo esc_html( $enabled ? $this->getIntegrationEnabledText() : $this->getIntegrationDisabledText() ); ?>
149
150 <a href="<?php echo esc_url( $this->getIntegrationsPageURL() ); ?>">
151 <?php esc_html_e( 'Manage integration', 'tier-pricing-table' ); ?> &rarr;
152 </a>
153 </div>
154 <?php endforeach; ?>
155
156 <?php $this->renderSupportedPlugins(); ?>
157
158 <?php $this->renderPromo( array_key_first( $competitors ) ); ?>
159
160 <?php else : ?>
161
162 <div class="tpt-pairing__intro">
163 <h3><?php echo esc_html( $this->getIntroHeading() ); ?></h3>
164 <p><?php echo esc_html( $this->getIntroText() ); ?></p>
165 </div>
166
167 <?php $this->renderSupportedPlugins(); ?>
168
169 <?php $this->renderPromo(); ?>
170
171 <?php endif; ?>
172
173 </div>
174 <?php
175 }
176
177 protected function renderSupportedPlugins() {
178 ?>
179 <div class="tpt-pairing__plugins">
180 <span class="tpt-pairing__plugins-label"><?php esc_html_e( 'Works with', 'tier-pricing-table' ); ?></span>
181 <?php foreach ( $this->getSupportedPlugins() as $plugin ) : ?>
182 <span class="tpt-pairing__plugin <?php echo $plugin['active'] ? 'tpt-pairing__plugin--active' : ''; ?>">
183 <i aria-hidden="true"></i>
184 <?php echo esc_html( $plugin['name'] ); ?>
185 <?php if ( $plugin['active'] ) : ?>
186 <em><?php esc_html_e( 'active', 'tier-pricing-table' ); ?></em>
187 <?php endif; ?>
188 </span>
189 <?php endforeach; ?>
190 </div>
191 <?php
192 }
193
194 protected function renderPromo( string $detectedCompetitor = '' ) {
195
196 $utm = '?utm_source=tiered-pricing-table&utm_medium=plugin&utm_campaign=' . $this->getUtmCampaignBase()
197 . ( $detectedCompetitor ? '-switch&utm_term=' . rawurlencode( $detectedCompetitor ) : '-tab' );
198
199 $iconURL = $this->getContainer()->getFileManager()->locateAsset( $this->getOwnPluginIconAsset() );
200
201 $title = $detectedCompetitor
202 /* translators: %s: U2Code plugin name */
203 ? sprintf( __( 'Switch to %s', 'tier-pricing-table' ), $this->getOwnPluginName() )
204 : $this->getOwnPluginName();
205 ?>
206 <div class="tpt-pairing__promo tpt-pairing__promo--<?php echo esc_attr( $this->getSlug() ); ?>">
207 <div class="tpt-pairing__promo-glow" aria-hidden="true"></div>
208
209 <div class="tpt-pairing__promo-content">
210 <div class="tpt-pairing__promo-head">
211 <span class="tpt-pairing__promo-icon">
212 <img src="<?php echo esc_url( $iconURL ); ?>" width="52" height="52" alt="">
213 </span>
214 <div class="tpt-pairing__promo-title">
215 <h4><?php echo esc_html( $title ); ?></h4>
216 <div class="tpt-pairing__promo-badges">
217 <span class="tpt-integration-item__official-badge"><?php esc_html_e( 'By U2Code', 'tier-pricing-table' ); ?></span>
218 <span class="tpt-pairing__promo-free"><?php esc_html_e( 'Free', 'tier-pricing-table' ); ?></span>
219 </div>
220 </div>
221 </div>
222
223 <p class="tpt-pairing__promo-text"><?php echo esc_html( $this->getPromoText() ); ?></p>
224
225 <ul class="tpt-pairing__promo-features">
226 <?php foreach ( $this->getOwnPluginPills() as $pill ) : ?>
227 <li>
228 <svg viewBox="0 0 20 20" width="16" height="16" aria-hidden="true" focusable="false"><circle cx="10" cy="10" r="10" fill="currentColor" opacity=".14"/><path d="M6 10.4l2.6 2.6L14 7.6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
229 <?php echo esc_html( $pill ); ?>
230 </li>
231 <?php endforeach; ?>
232 </ul>
233
234 <div class="tpt-pairing__promo-actions">
235 <a class="tpt-pairing__promo-cta" target="_blank" rel="noopener" href="<?php echo esc_url( $this->getOwnPluginWporgURL() ); ?>">
236 <?php esc_html_e( 'Get it free on WordPress.org', 'tier-pricing-table' ); ?>
237 <svg viewBox="0 0 20 20" width="16" height="16" aria-hidden="true" focusable="false"><path d="M4 10h11M11 5l5 5-5 5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
238 </a>
239 <a class="tpt-pairing__promo-link" target="_blank" rel="noopener" href="<?php echo esc_url( $this->getOwnPluginSiteURL() . $utm ); ?>">
240 <?php esc_html_e( 'Learn more', 'tier-pricing-table' ); ?>
241 </a>
242 <span class="tpt-pairing__promo-trust"><?php esc_html_e( 'Same team, one support channel for both plugins.', 'tier-pricing-table' ); ?></span>
243 </div>
244 </div>
245
246 <div class="tpt-pairing__promo-banner" aria-hidden="true">
247 <img src="<?php echo esc_url( $this->getContainer()->getFileManager()->locateAsset( $this->getOwnPluginBannerAsset() ) ); ?>" width="772" height="250" alt="">
248 </div>
249 </div>
250 <?php
251 }
252 }
253