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
← All changes | src/Settings/CustomOptions/TPTTextTemplate.php +12 -10 6.4.0 → 8.0.2 View file →
@@ -1,7 +1,8 @@
1 1 <?php namespace TierPricingTable\Settings\CustomOptions;
2 2
3 3 use TierPricingTable\Core\ServiceContainerTrait;
4 +use TierPricingTable\Settings\Settings;
4 5
5 6 class TPTTextTemplate {
6 7
7 8 const FIELD_TYPE = 'tpt_text_template';
@@ -17,16 +18,15 @@
17 18
18 19 public function __construct() {
19 20 add_action( 'woocommerce_admin_field_' . self::FIELD_TYPE, array( $this, 'render' ) );
20 21
21 - add_action( 'admin_head', function () {
22 - ?>
23 - <script>
24 - var TPTAvailableCustomButtons = JSON.parse('<?php echo wp_kses_post( wp_json_encode( $this->getAvailableVariables() ) ); ?>');
25 - </script>
22 + add_action( 'admin_enqueue_scripts', function () {
23 + $assetName = Settings::SETTINGS_PAGE . '_script';
26 24
27 - <?php
28 - } );
25 + wp_add_inline_script( $assetName,
26 + 'const TPTAvailableCustomButtons = ' . wp_json_encode( $this->getAvailableVariables() ) . ';',
27 + 'before' );
28 + }, 999 );
29 29
30 30 add_filter( 'mce_external_plugins', function ( $plugins, $editor ) {
31 31 if ( $this->editorId === $editor ) {
32 32 $plugins['tiered-pricing-custom-mce-buttons'] = $this->getContainer()->getFileManager()->locateJSAsset( 'admin/mce' );
@@ -53,8 +53,10 @@
53 53
54 54 }
55 55
56 56 public function render( $value ) {
57 + // the description is plugin-defined text (settings arrays), read once for output
58 + $description = (string) ( $value['desc'] ?? '' );
57 59 if ( ! isset( $value['id'] ) ) {
58 60 $value['id'] = '';
59 61 }
60 62 if ( ! isset( $value['title'] ) ) {
@@ -127,9 +129,9 @@
127 129 ) );
128 130 ?>
129 131
130 132 <?php if ( $value['desc'] ) : ?>
131 - <p class="description"><?php echo wp_kses_post( $value['desc'] ); ?></p>
133 + <p class="description"><?php echo wp_kses_post( $description ); // nosemgrep ?></p>
132 134 <?php endif; ?>
133 135 </td>
134 136 </tr>
135 137 <?php
@@ -135,9 +137,9 @@
135 137 <?php
136 138 }
137 139
138 140 protected function getAvailableVariables() {
139 - return array(
141 + return apply_filters( 'tiered_pricing_table/text_template_variables', array(
140 142 'tp_quantity' => array(
141 143 'name' => __( 'Quantity', 'tier-pricing-table' ),
142 144 'description' => __( '{tp_quantity} - range or a static quantity of the current pricing tier.',
143 145 'tier-pricing-table' ),
@@ -212,7 +214,7 @@
212 214 'tier-pricing-table' ),
213 215 'variableKey' => '{tp_base_unit_name}',
214 216 ),
215 217
216 - );
218 + ) );
217 219 }
218 220 }