| 1 |
<?php namespace TierPricingTable\Addons\Tools\Settings; |
| 2 |
|
| 3 |
use TierPricingTable\Addons\GlobalTieredPricing\CPT\GlobalTieredPricingCPT; |
| 4 |
use TierPricingTable\Addons\Tools\PricingTest\PricingTester; |
| 5 |
use TierPricingTable\Settings\Settings as MainSettings; |
| 6 |
|
| 7 |
class Settings { |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
|
| 11 |
// the utilities panel on the Advanced tab, between the modules and the cache settings |
| 12 |
add_filter( 'tiered_pricing_table/settings/tools_settings', function ( $settings ) { |
| 13 |
return array_merge( array( |
| 14 |
array( |
| 15 |
// #roles: the "Manage roles" links land here, above the Utilities heading; the app also reads the hash as its tab |
| 16 |
'type' => 'tiered-pricing_tools-anchor', |
| 17 |
), |
| 18 |
array( |
| 19 |
'title' => __( 'Utilities', 'tier-pricing-table' ), |
| 20 |
'desc' => __( 'Manage roles, test what a customer pays, and clean up tiered pricing data.', 'tier-pricing-table' ), |
| 21 |
'id' => MainSettings::SETTINGS_PREFIX . 'tools_utilities', |
| 22 |
'type' => 'title', |
| 23 |
), |
| 24 |
array( |
| 25 |
'type' => 'tiered-pricing_tools-ui', |
| 26 |
), |
| 27 |
array( |
| 28 |
'type' => 'sectionend', |
| 29 |
'id' => MainSettings::SETTINGS_PREFIX . 'tools_utilities', |
| 30 |
), |
| 31 |
), $settings ); |
| 32 |
} ); |
| 33 |
|
| 34 |
add_action( 'woocommerce_admin_field_tiered-pricing_tools-anchor', function () { |
| 35 |
// printed between two settings tables, so it is not a table row; the scroll margin keeps the heading below the sticky bars |
| 36 |
?> |
| 37 |
<div id="roles" style="scroll-margin-top: 90px;"></div> |
| 38 |
<?php |
| 39 |
} ); |
| 40 |
|
| 41 |
add_action( 'woocommerce_admin_field_tiered-pricing_tools-ui', function () { |
| 42 |
?> |
| 43 |
<tr valign="top"> |
| 44 |
<td colspan="2" class="forminp"> |
| 45 |
<div id="tiered-pricing__feature__tools"></div> |
| 46 |
</td> |
| 47 |
</tr> |
| 48 |
<?php |
| 49 |
} ); |
| 50 |
|
| 51 |
add_action( 'admin_enqueue_scripts', function () { |
| 52 |
|
| 53 |
$settingsTab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : ''; |
| 54 |
$section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : ''; |
| 55 |
|
| 56 |
if ( MainSettings::SETTINGS_PAGE !== $settingsTab ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
if ( ! in_array( $section, array( 'advanced', 'tools' ), true ) ) { // 'tools' is the pre-7.2.1 link |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
$assetFile = include( plugin_dir_path( __FILE__ ) . '../build/index.asset.php' ); |
| 65 |
|
| 66 |
wp_enqueue_script( 'tiered-pricing/feature/tools', |
| 67 |
plugins_url( 'build/index.js', dirname( __FILE__ . '../' ) ), $assetFile['dependencies'], |
| 68 |
$assetFile['version'], true ); |
| 69 |
|
| 70 |
wp_set_script_translations( 'tiered-pricing/feature/tools', 'tier-pricing-table', |
| 71 |
dirname( __FILE__, 5 ) . '/languages' ); |
| 72 |
|
| 73 |
// a rule to highlight in the Pricing test, from the links on the rules screens |
| 74 |
$testRule = isset( $_GET[ PricingTester::RULE_PARAM ] ) ? absint( $_GET[ PricingTester::RULE_PARAM ] ) : 0; |
| 75 |
$testRule = $testRule && GlobalTieredPricingCPT::SLUG === get_post_type( $testRule ) ? $testRule : 0; |
| 76 |
|
| 77 |
wp_localize_script( 'tiered-pricing/feature/tools', 'tptToolsConfig', array( |
| 78 |
'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
| 79 |
'searchProductsNonce' => wp_create_nonce( 'search-products' ), |
| 80 |
'searchCustomersNonce' => wp_create_nonce( 'search-customers' ), |
| 81 |
'pricingTest' => array( |
| 82 |
'rulesEnabled' => PricingTester::rulesEnabled(), |
| 83 |
'rulesUrl' => admin_url( 'edit.php?post_type=' . GlobalTieredPricingCPT::SLUG ), |
| 84 |
'newRuleUrl' => admin_url( 'post-new.php?post_type=' . GlobalTieredPricingCPT::SLUG ), |
| 85 |
'rule' => $testRule ? array( |
| 86 |
'id' => $testRule, |
| 87 |
'title' => PricingTester::ruleTitle( $testRule ), |
| 88 |
'url' => get_edit_post_link( $testRule, 'raw' ), |
| 89 |
) : null, |
| 90 |
), |
| 91 |
) ); |
| 92 |
|
| 93 |
wp_enqueue_style( 'wp-components' ); |
| 94 |
} ); |
| 95 |
} |
| 96 |
} |
| 97 |
|