PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.1
1.7.1 1.7.0 1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 All 51 releases
← All changes | api/StoreSettings.php +728 -4 1.6.3 → 1.7.1 View file →
@@ -7,8 +7,12 @@
7 7 use FluentCart\App\CPT\Pages;
8 8 use FluentCart\App\Helpers\AddressHelper;
9 9 use FluentCart\App\Helpers\CurrenciesHelper;
10 10 use FluentCart\App\Services\OrderService;
11 +use FluentCart\App\Services\Theme\ColorPalette;
12 +use FluentCart\App\Services\Theme\FrontendTheme;
13 +use FluentCart\App\Services\Theme\RadiusPalette;
14 +use FluentCart\App\Services\Theme\ThemePalette;
11 15 use FluentCart\App\Modules\PaymentMethods\Core\GatewayManager;
12 16 use FluentCart\App\Modules\StoreManagedRenewal\Services\RenewalService;
13 17 use FluentCart\App\Modules\Subscriptions\Services\SubscriptionManagementMode;
14 18 use FluentCart\Framework\Support\Arr;
@@ -80,8 +84,10 @@
80 84 'show_cart_icon_in_body' => 'yes',
81 85 'additional_address_field' => 'yes',
82 86 'hide_coupon_field' => 'no',
83 87 'user_account_creation_mode' => 'all',
88 + 'auto_login_after_account_creation' => 'yes',
89 + 'require_customer_email_verification' => 'no',
84 90 'checkout_page_id' => '',
85 91 'custom_payment_page_id' => '',
86 92 'registration_page_id' => '',
87 93 'login_page_id' => '',
@@ -86,8 +92,9 @@
86 92 'registration_page_id' => '',
87 93 'login_page_id' => '',
88 94 'cart_page_id' => '',
89 95 'receipt_page_id' => '',
96 + 'order_review_page_id' => '',
90 97 'shop_page_id' => '',
91 98 'customer_profile_page_id' => '',
92 99 'customer_profile_page_slug' => '',
93 100 'currency' => 'USD',
@@ -98,9 +105,13 @@
98 105 'store_postcode' => '',
99 106 'store_state' => '',
100 107 'show_relevant_product_in_single_page' => 'yes',
101 108 'show_relevant_product_in_modal' => '',
109 + 'show_reviews_in_single_page' => 'yes',
110 + 'show_rating_in_shop' => 'yes',
111 + 'show_rating_in_relevant' => 'yes',
102 112 'order_mode' => 'test',
113 + 'subscription_mode_guard' => 'yes',
103 114 'variation_view' => 'both',
104 115 'variation_columns' => 'masonry',
105 116 'enable_early_payment_for_installment' => 'yes',
106 117 'subscription_management_mode' => 'gateway_managed',
@@ -108,9 +119,20 @@
108 119 'modules_settings' => [],
109 120 'min_receipt_number' => '1',
110 121 'inv_prefix' => 'INV-',
111 122 'weight_unit' => 'kg',
112 - 'dimension_unit' => 'cm'
123 + 'dimension_unit' => 'cm',
124 + 'appearance_source' => ColorPalette::SOURCE_DEFAULT,
125 + 'appearance_colors' => [],
126 + 'appearance_radius' => [],
127 + // 'wordpress', not 'fluent_cart': the FluentCart patterns are
128 + // literals ('M j, Y'), and a literal renders a half-translated date
129 + // on a localized store -- a German month in English field order,
130 + // which a German reader misreads as day-first. Following
131 + // Settings > General is the only source that is correct in every
132 + // locale, so it is what a store gets until it chooses otherwise.
133 + 'date_time_format_source' => 'wordpress',
134 + 'timezone_source' => 'fluent_cart'
113 135 ];
114 136
115 137 return apply_filters('fluent_cart/store_settings/values', $defaultSettings, []);
116 138 }
@@ -129,9 +151,10 @@
129 151 'shop_page_id' => $this->getShopPage(),
130 152 'customer_profile_page_id' => $this->getCustomerProfilePage(),
131 153 'cart_page_id' => $this->getCartPage(),
132 154 'checkout_page_id' => $this->getCheckoutPage(),
133 - 'receipt_page_id' => $this->getReceiptPage()
155 + 'receipt_page_id' => $this->getReceiptPage(),
156 + 'order_review_page_id' => $this->getOrderReviewPage()
134 157 ];
135 158 $isProActive = App::isProActive();
136 159 $proFeatureIcon = Vite::getAssetUrl('images/crown.svg');
137 160
@@ -297,9 +320,9 @@
297 320 ],
298 321 ]
299 322 ],
300 323
301 - 'settings_hr' => [
324 + 'date_time_hr' => [
302 325 'type' => 'html',
303 326 'value' => '<hr class="settings-divider">'
304 327 ],
305 328
@@ -565,8 +588,79 @@
565 588 ],
566 589 ]
567 590 ],
568 591
592 + 'settings_hr' => [
593 + 'type' => 'html',
594 + 'value' => '<hr class="settings-divider">'
595 + ],
596 +
597 + 'date_time_format_grid' => [
598 + 'type' => 'grid',
599 + 'columns' => [
600 + 'default' => 1,
601 + 'md' => 3
602 + ],
603 + 'disable_nesting' => true,
604 + 'schema' => [
605 + 'label' => [
606 + 'type' => 'html',
607 + 'value' => '<span class="setting-label">' . __('Date & Time Format', 'fluent-cart') . '</span>
608 + <div class="form-note">' . __("Which date and time format to display. `Smart` keeps FluentCart's own format; `WordPress` follows Settings &rarr; General.", 'fluent-cart') . '</div>'
609 + ],
610 + 'date_time_format_source' => [
611 + 'wrapperClass' => 'col-span-2 flex items-center',
612 + 'label' => '',
613 + 'type' => 'radio',
614 + 'options' => [
615 + [
616 + // Label only -- the stored value stays 'fluent_cart'.
617 + 'label' => __('Smart', 'fluent-cart'),
618 + 'value' => 'fluent_cart',
619 + ],
620 + [
621 + 'label' => __('WordPress', 'fluent-cart'),
622 + 'value' => 'wordpress',
623 + ],
624 + ],
625 + 'value' => 'fluent_cart'
626 + ],
627 + ]
628 + ],
629 +
630 + 'timezone_source_grid' => [
631 + 'type' => 'grid',
632 + 'columns' => [
633 + 'default' => 1,
634 + 'md' => 3
635 + ],
636 + 'disable_nesting' => true,
637 + 'schema' => [
638 + 'label' => [
639 + 'type' => 'html',
640 + 'value' => '<span class="setting-label">' . __('Timezone', 'fluent-cart') . '</span>
641 + <div class="form-note">' . __("Which timezone to display dates in. `Browser` shows admin and dashboard dates in the viewer's own timezone, and renders emails and invoices in the timezone captured at checkout; `WordPress` uses the site timezone from Settings &rarr; General.", 'fluent-cart') . '</div>'
642 + ],
643 + 'timezone_source' => [
644 + 'wrapperClass' => 'col-span-2 flex items-center',
645 + 'label' => '',
646 + 'type' => 'radio',
647 + 'options' => [
648 + [
649 + // Label only -- the stored value stays 'fluent_cart'.
650 + 'label' => __('Browser', 'fluent-cart'),
651 + 'value' => 'fluent_cart',
652 + ],
653 + [
654 + 'label' => __('WordPress', 'fluent-cart'),
655 + 'value' => 'wordpress',
656 + ],
657 + ],
658 + 'value' => 'fluent_cart'
659 + ],
660 + ]
661 + ],
662 +
569 663 // 'settings_hr_modal' => [
570 664 // 'type' => 'html',
571 665 // 'value' => '<hr class="settings-divider">'
572 666 // ],
@@ -807,8 +901,45 @@
807 901 ],
808 902 ]
809 903 ],
810 904
905 + 'hr_order_review' => [
906 + 'type' => 'html',
907 + 'value' => '<hr class="settings-divider">'
908 + ],
909 +
910 + 'order_review_page_grid' => [
911 + 'type' => 'grid',
912 + 'columns' => [
913 + 'default' => 1,
914 + 'md' => 3
915 + ],
916 + 'disable_nesting' => true,
917 + 'schema' => [
918 + 'label' => [
919 + 'type' => 'html',
920 + 'value' => '<span class="setting-label">' . __('Select Order Review Page', 'fluent-cart') . '</span>
921 + <div class="form-note">' . __("Select the page where customers will review the products they bought, from the link in their order email.", 'fluent-cart') . '</div>'
922 + ],
923 + 'order_review_page_id' => [
924 + 'wrapperClass' => 'col-span-2',
925 + 'label' => false,
926 + 'page_title' => __('Review Your Order', 'fluent-cart'),
927 + 'type' => 'component',
928 + 'component' => 'StoreSettings/PageSelector',
929 + 'page_key' => 'order_review_page_id',
930 + 'preview_link' => $previewLinks['order_review_page_id'],
931 + 'hide_note' => true,
932 + 'options' => $pages,
933 + 'value' => '',
934 + 'note' => \FluentCart\App\Helpers\Helper::getShortcodeInstructionString(
935 + '[fluent_cart_order_review]',
936 + __('Review Your Order', 'fluent-cart')
937 + ),
938 + ],
939 + ]
940 + ],
941 +
811 942 'hr4' => [
812 943 'type' => 'html',
813 944 'value' => '<hr class="settings-divider">'
814 945 ],
@@ -866,9 +997,9 @@
866 997 'schema' => [
867 998 'label' => [
868 999 'type' => 'html',
869 1000 'value' => '<span class="setting-label">' . __('Single Product Setup', 'fluent-cart') . '</span>
870 - <div class="form-note">' . __("Control the display of relevant information.", 'fluent-cart') . '</div>'
1001 + <div class="form-note">' . __("Choose which sections to display on the single product page.", 'fluent-cart') . '</div>'
871 1002 ],
872 1003 'fields' => [
873 1004 'type' => 'grid',
874 1005 'columns' => [
@@ -886,8 +1017,17 @@
886 1017 "label" => __('Show Relevant In Product Modal', 'fluent-cart'),
887 1018 "type" => "checkbox",
888 1019 "value" => "no"
889 1020 ],
1021 + "show_reviews_in_single_page" => [
1022 + "label" => __('Show Reviews In Single Page', 'fluent-cart'),
1023 + "type" => "checkbox",
1024 + "value" => "yes"
1025 + ],
1026 + "show_reviews_note" => [
1027 + "type" => "html",
1028 + "value" => '<div class="form-note">' . __('For block themes, add the Product Reviews block to your Single Product template to display reviews on your product page.', 'fluent-cart') . '</div>'
1029 + ],
890 1030 ]
891 1031 ]
892 1032
893 1033 ]
@@ -1049,10 +1189,159 @@
1049 1189 ],
1050 1190
1051 1191 ]
1052 1192 ],
1193 +
1194 + 'hr_product_slug' => [
1195 + 'type' => 'html',
1196 + 'value' => '<hr class="settings-divider">'
1197 + ],
1198 +
1199 + 'product_rating_grid' => [
1200 + 'type' => 'grid',
1201 + 'columns' => [
1202 + 'default' => 1,
1203 + 'md' => 3
1204 + ],
1205 + 'disable_nesting' => true,
1206 + 'schema' => [
1207 + 'label' => [
1208 + 'type' => 'html',
1209 + 'value' => sprintf(
1210 + '<span class="setting-label">%1$s</span><div class="form-note">%2$s</div>',
1211 + __('Product Rating', 'fluent-cart'),
1212 + __('Show star ratings when reviews are enabled.', 'fluent-cart')
1213 + )
1214 + ],
1215 + 'fields' => [
1216 + 'type' => 'grid',
1217 + 'columns' => [
1218 + 'default' => 1,
1219 + 'md' => 1
1220 + ],
1221 + 'disable_nesting' => true,
1222 + 'schema' => [
1223 + "show_rating_in_shop" => [
1224 + "label" => __('Show Rating in Shop', 'fluent-cart'),
1225 + "type" => "checkbox",
1226 + "value" => "yes"
1227 + ],
1228 + "show_rating_in_relevant" => [
1229 + "label" => __('Show Rating in Relevant Products', 'fluent-cart'),
1230 + "type" => "checkbox",
1231 + "value" => "yes"
1232 + ],
1233 + ]
1234 + ]
1235 +
1236 + ]
1237 + ],
1053 1238 ],
1054 1239 ],
1240 + 'compliance' => [
1241 + 'title' => __('Compliance', 'fluent-cart'),
1242 + 'show_title' => false,
1243 + 'type' => 'section',
1244 + 'disable_nesting' => true,
1245 + 'columns' => [
1246 + 'default' => 1,
1247 + 'md' => 1,
1248 + ],
1249 + 'schema' => [
1250 + 'email_verification_grid' => [
1251 + 'type' => 'grid',
1252 + 'disable_nesting' => true,
1253 + 'columns' => ['default' => 1, 'md' => 3],
1254 + 'wrapperClass' => 'items-start',
1255 + 'schema' => [
1256 + 'label' => [
1257 + 'type' => 'html',
1258 + 'value' => sprintf(
1259 + '<span class="setting-label">%1$s</span><div class="form-note">%2$s</div>',
1260 + esc_html__('Customer email verification', 'fluent-cart'),
1261 + esc_html__('Confirm email ownership before customers access their portal and saved checkout addresses.', 'fluent-cart')
1262 + ),
1263 + ],
1264 + 'fields' => [
1265 + 'type' => 'grid',
1266 + 'disable_nesting' => true,
1267 + 'columns' => ['default' => 1],
1268 + 'wrapperClass' => 'md:col-span-2',
1269 + 'schema' => [
1270 + 'require_customer_email_verification' => [
1271 + 'wrapperClass' => 'fct-compliance-auto-login',
1272 + 'label' => false,
1273 + 'type' => 'radio',
1274 + 'value' => 'no',
1275 + 'attributes' => [
1276 + 'aria-label' => __('Customer email verification', 'fluent-cart'),
1277 + ],
1278 + 'options' => [
1279 + [
1280 + 'label' => __('Required', 'fluent-cart'),
1281 + 'value' => 'yes',
1282 + ],
1283 + [
1284 + 'label' => __('Not required', 'fluent-cart'),
1285 + 'value' => 'no',
1286 + ],
1287 + ],
1288 + 'note' => __('When not required, new checkout accounts are linked to their purchases immediately.', 'fluent-cart'),
1289 + ],
1290 + ],
1291 + ],
1292 + ],
1293 + ],
1294 + 'compliance_divider' => [
1295 + 'type' => 'html',
1296 + 'value' => '<hr class="settings-divider">',
1297 + ],
1298 + 'account_login_grid' => [
1299 + 'type' => 'grid',
1300 + 'disable_nesting' => true,
1301 + 'columns' => ['default' => 1, 'md' => 3],
1302 + 'wrapperClass' => 'items-start',
1303 + 'schema' => [
1304 + 'label' => [
1305 + 'type' => 'html',
1306 + 'value' => sprintf(
1307 + '<span class="setting-label">%1$s</span><div class="form-note">%2$s</div>',
1308 + esc_html__('Login after account creation', 'fluent-cart'),
1309 + esc_html__('Choose how customers sign in after registering or completing checkout.', 'fluent-cart')
1310 + ),
1311 + ],
1312 + 'fields' => [
1313 + 'type' => 'grid',
1314 + 'disable_nesting' => true,
1315 + 'columns' => ['default' => 1],
1316 + 'wrapperClass' => 'md:col-span-2',
1317 + 'schema' => [
1318 + 'auto_login_after_account_creation' => [
1319 + 'wrapperClass' => 'fct-compliance-auto-login',
1320 + 'label' => false,
1321 + 'type' => 'radio',
1322 + 'value' => 'yes',
1323 + 'attributes' => [
1324 + 'aria-label' => __('Login after account creation', 'fluent-cart'),
1325 + ],
1326 + 'options' => [
1327 + [
1328 + 'label' => __('Log in automatically', 'fluent-cart'),
1329 + 'value' => 'yes',
1330 + ],
1331 + [
1332 + 'label' => __('Let customers log in', 'fluent-cart'),
1333 + 'value' => 'no',
1334 + ],
1335 + ],
1336 + 'note' => __('Email verification still applies when required above.', 'fluent-cart'),
1337 + ],
1338 + ],
1339 + ],
1340 + ],
1341 + ],
1342 + ],
1343 + ],
1055 1344 'cart_and_checkout' => [
1056 1345 'title' => __('Cart & checkout', 'fluent-cart'),
1057 1346 'show_title' => false,
1058 1347 'type' => 'section',
@@ -1316,10 +1605,53 @@
1316 1605 ]
1317 1606 ]
1318 1607 ]
1319 1608 ],
1609 + 'subscription_mode_guard_grid' => [
1610 + 'type' => 'grid',
1611 + 'wrapperClass' => 'items-start mt-6',
1612 + 'columns' => [
1613 + 'default' => 1,
1614 + 'md' => 3
1615 + ],
1616 + 'disable_nesting' => true,
1617 + 'schema' => [
1618 + 'label' => [
1619 + 'type' => 'html',
1620 + 'value' => sprintf(
1621 + /* translators: 1: setting label, 2: setting description */
1622 + '<span class="setting-label">%1$s</span>
1623 + <div class="form-note">%2$s</div>',
1624 + __('Staging Protection', 'fluent-cart'),
1625 + __('Prevent staging or test copies of your store from billing real customers.', 'fluent-cart')
1626 + )
1627 + ],
1628 + 'fields' => [
1629 + 'type' => 'grid',
1630 + 'columns' => [
1631 + 'default' => 1,
1632 + 'md' => 1
1633 + ],
1634 + 'disable_nesting' => true,
1635 + 'class' => 'col-span-2',
1636 + 'schema' => [
1637 + 'subscription_mode_guard' => [
1638 + 'label' => __('Don\'t bill live subscriptions from this site while it is in test mode', 'fluent-cart'),
1639 + 'type' => 'checkbox',
1640 + 'value' => 'yes',
1641 + 'note' => sprintf(
1642 + /* translators: 1: the setting's explanatory note text */
1643 + "<div class='pl-6'>%1\$s</div>",
1644 + __('In test mode, this site won\'t invoice, charge, or email live subscriptions — so a staging copy can never double-bill customers. Billing from this site resumes when it is live again.', 'fluent-cart')
1645 + )
1646 + ],
1647 + ]
1648 + ]
1649 + ]
1650 + ],
1320 1651 ]
1321 1652 ],
1653 + 'appearance' => $this->getAppearanceSchema(),
1322 1654 ]
1323 1655 ],
1324 1656 ];
1325 1657
@@ -1326,8 +1658,14 @@
1326 1658
1327 1659 // Only show weight/dimension unit fields to users with shipping-sensitive permission
1328 1660 if (PermissionManager::hasPermission(['store/sensitive'])) {
1329 1661 $storeSchema = &$fields['setting_tabs']['schema']['store_setup']['schema'];
1662 +
1663 + $storeSchema['weight_unit_grid_divider'] = [
1664 + 'type' => 'html',
1665 + 'value' => '<hr class="settings-divider">'
1666 + ];
1667 +
1330 1668 $storeSchema['weight_unit_grid'] = [
1331 1669 'type' => 'grid',
1332 1670 'columns' => ['default' => 1, 'md' => 3],
1333 1671 'disable_nesting' => true,
@@ -1376,8 +1714,25 @@
1376 1714 ]
1377 1715 ];
1378 1716 }
1379 1717
1718 + // Review settings only apply while the reviews module is active —
1719 + // hide them (and their dividers) otherwise: the Product Rating
1720 + // section, the "Show Reviews In Single Page" toggle with its note,
1721 + // and the Order Review page selector. The stored values survive:
1722 + // save() merges the submitted form over what is stored, so a field
1723 + // left off the form keeps its value for when the module returns.
1724 + if (!ModuleSettings::isActive('reviews')) {
1725 + unset(
1726 + $fields['setting_tabs']['schema']['single_product_setup']['schema']['hr_product_slug'],
1727 + $fields['setting_tabs']['schema']['single_product_setup']['schema']['product_rating_grid'],
1728 + $fields['setting_tabs']['schema']['single_product_setup']['schema']['product_settings_grid']['schema']['fields']['schema']['show_reviews_in_single_page'],
1729 + $fields['setting_tabs']['schema']['single_product_setup']['schema']['product_settings_grid']['schema']['fields']['schema']['show_reviews_note'],
1730 + $fields['setting_tabs']['schema']['pages_setup']['schema']['hr_order_review'],
1731 + $fields['setting_tabs']['schema']['pages_setup']['schema']['order_review_page_grid']
1732 + );
1733 + }
1734 +
1380 1735 return apply_filters("fluent_cart/store_settings/fields", $fields, []);
1381 1736 }
1382 1737
1383 1738 public function isModuleTabEnabled(): bool
@@ -1407,8 +1762,28 @@
1407 1762
1408 1763 return empty($data) ? $default : $data;
1409 1764 }
1410 1765
1766 + /**
1767 + * All store settings, as the settings form should edit them.
1768 + *
1769 + * A stored radius the grammar refuses (hand-edited, or written by an older
1770 + * build) never printed on the storefront; dropped here too, so the form
1771 + * never holds a value it would refuse to save.
1772 + *
1773 + * @return array
1774 + */
1775 + public function getForEditing(): array
1776 + {
1777 + $settings = (array)$this->get();
1778 +
1779 + if (array_key_exists('appearance_radius', $settings)) {
1780 + $settings['appearance_radius'] = RadiusPalette::sanitizeOwnerMap($settings['appearance_radius']);
1781 + }
1782 +
1783 + return $settings;
1784 + }
1785 +
1411 1786 public function moduleSettings(): array
1412 1787 {
1413 1788 $settings = $this->get('modules_settings', []);
1414 1789 return Arr::wrap($settings);
@@ -1468,8 +1843,11 @@
1468 1843
1469 1844 public function isCheckoutPage(): bool
1470 1845 {
1471 1846 global $post;
1847 + if (!$post instanceof \WP_Post) {
1848 + return false;
1849 + }
1472 1850 $pageId = $this->getCheckoutPageId();
1473 1851 return intval($pageId) === intval($post->ID);
1474 1852 }
1475 1853
@@ -1488,8 +1866,9 @@
1488 1866 'registration_page_id',
1489 1867 'login_page_id',
1490 1868 'cart_page_id',
1491 1869 'receipt_page_id',
1870 + 'order_review_page_id',
1492 1871 'shop_page_id',
1493 1872 'customer_profile_page_id',
1494 1873 'customer_profile_page_slug',
1495 1874 ]
@@ -1565,9 +1944,29 @@
1565 1944 }
1566 1945 return home_url();
1567 1946 }
1568 1947
1948 + public function getOrderReviewPageId()
1949 + {
1950 + return Arr::get($this->storeSettings, 'order_review_page_id');
1951 + }
1569 1952
1953 + /**
1954 + * The page hosting [fluent_cart_order_review], or home_url() when the store
1955 + * has not picked one — Order::getOrderReviewUrl() then falls back to the
1956 + * ?fluent-cart=order-review route, which needs no page at all.
1957 + */
1958 + public function getOrderReviewPage(): string
1959 + {
1960 + if ($pageId = $this->getOrderReviewPageId()) {
1961 + if (Pages::isPage($pageId)) {
1962 + return $this->getPageLink($pageId);
1963 + }
1964 + }
1965 + return home_url();
1966 + }
1967 +
1968 +
1570 1969 public function getBuyButtonText(): string
1571 1970 {
1572 1971 return esc_html(Arr::get($this->storeSettings, 'checkout_button_text', __('Buy now', 'fluent-cart')));
1573 1972 }
@@ -1710,8 +2109,333 @@
1710 2109 return $slug;
1711 2110 }
1712 2111
1713 2112 return trim(str_replace(home_url('/'), '', $url), '/');
2113 + }
2114 +
2115 + /**
2116 + * The Appearance settings tab.
2117 + *
2118 + * Built from the ColorPalette registry rather than written out by hand, so
2119 + * a colour added to the registry becomes settable here, sanitised on save
2120 + * and written to the storefront without three separate edits.
2121 + *
2122 + * @return array
2123 + */
2124 + protected function getAppearanceSchema(): array
2125 + {
2126 + // Plain text — the component renders these as text nodes, so no markup
2127 + // and no escaping here or the entities would show up verbatim.
2128 + $sourceOptions = [
2129 + [
2130 + 'label' => __("FluentCart's own style", 'fluent-cart'),
2131 + 'value' => ColorPalette::SOURCE_DEFAULT,
2132 + 'icon' => 'PaletteLine',
2133 + 'note' => __('The storefront keeps the colors and corner rounding it ships with.', 'fluent-cart'),
2134 + ],
2135 + [
2136 + 'label' => __('Inherit from the active theme', 'fluent-cart'),
2137 + 'value' => ColorPalette::SOURCE_THEME,
2138 + 'icon' => 'PaintLine',
2139 + 'note' => __('FluentCart uses your active theme\'s colors, and its button and form field corner rounding, for the storefront. Product cards keep FluentCart\'s corners. If something doesn\'t come through as expected, choose Customize to set it yourself.', 'fluent-cart'),
2140 + ],
2141 + [
2142 + 'label' => __('Customize', 'fluent-cart'),
2143 + 'value' => ColorPalette::SOURCE_CUSTOM,
2144 + 'icon' => 'PaletteLine',
2145 + 'note' => __('Pick the colors and corner rounding yourself. Only what you set is written to the storefront.', 'fluent-cart'),
2146 + ],
2147 + ];
2148 +
2149 + $sourceHeading = [
2150 + 'label' => __('Where colors and corner rounding come from', 'fluent-cart'),
2151 + 'note' => __('Storefront colors and corner rounding cascade from a small set of globals, so changing one here updates every page that uses it.', 'fluent-cart'),
2152 + ];
2153 +
2154 + return [
2155 + 'title' => __('Appearance', 'fluent-cart'),
2156 + 'show_title' => false,
2157 + 'type' => 'section',
2158 + 'wrapperClass' => 'fct-appearance-component-section',
2159 + 'disable_nesting' => true,
2160 + 'columns' => [
2161 + 'default' => 1,
2162 + 'md' => 1,
2163 + ],
2164 + 'schema' => [
2165 + 'appearance_component' => [
2166 + 'type' => 'component',
2167 + 'component' => 'StoreSettings/AppearanceComponent',
2168 + 'wrapperClass' => 'col-span-full',
2169 + 'label' => false,
2170 + // Rendered by the component itself, so the heading sits
2171 + // inside .fct-appearance-component with the controls it
2172 + // describes rather than as a sibling html field.
2173 + 'heading' => $sourceHeading,
2174 + 'source_options' => $sourceOptions,
2175 + 'custom_source' => ColorPalette::SOURCE_CUSTOM,
2176 + 'color_groups' => $this->getAppearanceColorGroups(),
2177 + 'radius_section' => $this->getAppearanceRadiusSection(),
2178 + 'preview' => $this->getAppearancePreviewData(),
2179 + ],
2180 + 'appearance_source' => [
2181 + 'type' => 'hidden',
2182 + 'value' => ColorPalette::SOURCE_DEFAULT,
2183 + ],
2184 + 'appearance_colors' => [
2185 + 'type' => 'hidden',
2186 + 'value' => (object)[],
2187 + ],
2188 + 'appearance_radius' => [
2189 + 'type' => 'hidden',
2190 + 'value' => (object)[],
2191 + ],
2192 + ],
2193 + ];
2194 + }
2195 +
2196 + /**
2197 + * What the storefront preview needs to paint itself.
2198 + *
2199 + * The preview is drawn from semantic roles rather than settings keys, so
2200 + * one mock card covers all three sources: `customize` reads the pickers the
2201 + * owner has filled in, and the other two are resolved here because their
2202 + * colors only exist server side — `inherit_from_theme` is mixed out of
2203 + * theme.json by ThemePalette and nothing about it reaches the browser.
2204 + *
2205 + * @return array
2206 + */
2207 + protected function getAppearancePreviewData(): array
2208 + {
2209 + // No colour is sent with a slot. appearance.scss already writes every
2210 + // preview surface as `var(--fct-pv-x, <fallback>)`, so the mock has the
2211 + // same single source of truth the storefront does: a slot the component
2212 + // cannot resolve simply goes undeclared and the stylesheet's fallback
2213 + // applies.
2214 + return [
2215 + 'slots' => $this->getAppearancePreviewSlots(),
2216 + 'theme_source' => ColorPalette::SOURCE_THEME,
2217 + 'theme_roles' => $this->getAppearanceThemeRoles(),
2218 + 'theme_radii' => $this->getAppearanceThemeRadii(),
2219 + 'notes' => [
2220 + ColorPalette::SOURCE_THEME => $this->getAppearanceThemeNote(),
2221 + ColorPalette::SOURCE_CUSTOM => __('Set only the colors you want to change — anything you leave unset keeps FluentCart\'s own default.', 'fluent-cart'),
2222 + ],
2223 + ];
2224 + }
2225 +
2226 + /**
2227 + * Which custom property the preview paints each surface with.
2228 + *
2229 + * Keyed by settings key, not by role. Four separate globals claim the
2230 + * `accent` role — active text, the brand background and both active
2231 + * borders — so collapsing the preview to roles would let one picker drive
2232 + * surfaces the storefront keeps apart, and leave the others with no visible
2233 + * effect at all. `role` is carried only for theme inheritance, which
2234 + * genuinely is role-based: FrontendTheme::getThemeColors() gives every key
2235 + * sharing a role the same colour, so the preview collapsing there is the
2236 + * storefront's own behaviour rather than a shortcut.
2237 + *
2238 + * A slot with no `key` is a surface no global controls; it follows the
2239 + * role's default and cannot be edited.
2240 + *
2241 + * @return array
2242 + */
2243 + protected function getAppearancePreviewSlots(): array
2244 + {
2245 + return [
2246 + ['var' => 'surface', 'role' => 'surface', 'key' => 'card_bg_color'],
2247 + ['var' => 'surface-mute', 'role' => 'surface_mute'],
2248 + ['var' => 'surface-alt', 'role' => 'surface_alt', 'key' => 'secondary_bg_color'],
2249 + ['var' => 'text', 'role' => 'text', 'key' => 'primary_text_color'],
2250 + ['var' => 'text-muted', 'role' => 'text_muted', 'key' => 'secondary_text_color'],
2251 + ['var' => 'text-placeholder', 'role' => 'text_placeholder', 'key' => 'input_placeholder_text_color'],
2252 + ['var' => 'input-bg', 'role' => 'surface', 'key' => 'input_bg_color'],
2253 + ['var' => 'input-text', 'role' => 'text', 'key' => 'input_text_color'],
2254 + ['var' => 'input-disabled-bg', 'role' => 'surface_mute', 'key' => 'input_disabled_bg_color'],
2255 + ['var' => 'accent-text', 'role' => 'accent', 'key' => 'primary_active_text_color'],
2256 + ['var' => 'active-border', 'role' => 'accent', 'key' => 'active_border_color'],
2257 + ['var' => 'border', 'role' => 'border', 'key' => 'border_color'],
2258 + ['var' => 'divider', 'role' => 'divider', 'key' => 'divider_color'],
2259 + ['var' => 'button-bg', 'role' => 'button_bg', 'key' => 'btn_bg_color'],
2260 + ['var' => 'button-text', 'role' => 'button_text', 'key' => 'btn_text_color'],
2261 + ['var' => 'secondary-button-bg', 'role' => 'surface', 'key' => 'secondary_btn_bg_color'],
2262 + ['var' => 'secondary-button-text', 'role' => 'text', 'key' => 'secondary_btn_text_color'],
2263 + ['var' => 'secondary-button-border', 'role' => 'border', 'key' => 'secondary_btn_border_color'],
2264 + ['var' => 'secondary-button-hover-bg', 'role' => 'surface_mute', 'key' => 'secondary_btn_hover_bg_color'],
2265 + ];
2266 + }
2267 +
2268 + /**
2269 + * Why the theme preview may not be the whole truth.
2270 + *
2271 + * Themes such as Astra publish their palette as `var(--ast-global-color-0)`
2272 + * rather than as colors. FrontendTheme writes those references straight
2273 + * through and the browser resolves them on the storefront, but the property
2274 + * is not declared in wp-admin, so the preview cannot show them. Saying so
2275 + * beats showing FluentCart's colors and letting the owner believe that is
2276 + * what inheriting will look like.
2277 + *
2278 + * @return string Empty when the preview is faithful.
2279 + */
2280 + protected function getAppearanceThemeNote(): string
2281 + {
2282 + if (!ThemePalette::hasUsableSource()) {
2283 + return __('The active theme publishes no colors to inherit, so the storefront keeps FluentCart\'s own colors.', 'fluent-cart');
2284 + }
2285 +
2286 + // Only a colour with no hex anywhere is unpreviewable. A live
2287 + // reference with a hex fallback — what the theme-settings readers and
2288 + // Blocksy write — previews as that fallback.
2289 + foreach (ThemePalette::resolve() as $value) {
2290 + if ((string)$value !== '' && ThemePalette::measurable((string)$value) === '') {
2291 + return __('This theme publishes its palette as CSS variables. The storefront reads them, but they cannot be resolved here — the preview shows FluentCart\'s colors in their place.', 'fluent-cart');
2292 + }
2293 + }
2294 +
2295 + return '';
2296 + }
2297 +
2298 + /**
2299 + * The theme's colors for the preview, role by role.
2300 + *
2301 + * Only roles that resolved to a real color are returned — the preview
2302 + * falls back to each slot's own default for the rest.
2303 + *
2304 + * @return array Role => hex.
2305 + */
2306 + protected function getAppearanceThemeRoles(): array
2307 + {
2308 + // With nothing to inherit, FrontendTheme writes no declarations at all,
2309 + // so the storefront keeps FluentCart's colors — and so must the
2310 + // preview, or it would promise a change that never happens.
2311 + if (!ThemePalette::hasUsableSource()) {
2312 + return [];
2313 + }
2314 +
2315 + $roles = [];
2316 +
2317 + foreach (ThemePalette::resolve() as $role => $value) {
2318 + // A theme that publishes a bare `var(--x)` is written to the
2319 + // storefront verbatim and resolved by the browser there, but that
2320 + // property is not declared in wp-admin. Unpreviewable, so leave it
2321 + // out and let the slot fall back to its own default. A reference
2322 + // with a hex fallback (`var(--x, #hex)`) previews as that hex —
2323 + // the same colour the storefront measures it by.
2324 + $hex = ThemePalette::measurable((string)$value);
2325 +
2326 + if ($hex) {
2327 + $roles[$role] = $hex;
2328 + }
2329 + }
2330 +
2331 + return $roles;
2332 + }
2333 +
2334 + /**
2335 + * The theme's border radii for the preview, role => length.
2336 + *
2337 + * Exactly what inheriting would print, storefront filter included, so the
2338 + * preview never promises a radius the storefront won't write.
2339 + *
2340 + * @return array Role key => length (`8px`, `0.5rem`).
2341 + */
2342 + protected function getAppearanceThemeRadii(): array
2343 + {
2344 + return FrontendTheme::radiiFor(ColorPalette::SOURCE_THEME);
2345 + }
2346 +
2347 + /**
2348 + * The colour knobs, grouped the way the registry groups them, as data the
2349 + * appearance component renders its pickers from.
2350 + *
2351 + * @return array
2352 + */
2353 + protected function getAppearanceColorGroups(): array
2354 + {
2355 + $groups = [];
2356 +
2357 + foreach (ColorPalette::groups() as $groupKey => $groupLabel) {
2358 + $globals = ColorPalette::globalsFor($groupKey);
2359 +
2360 + if (!$globals) {
2361 + continue;
2362 + }
2363 +
2364 + $fields = [];
2365 +
2366 + foreach ($globals as $key => $definition) {
2367 + $fields[] = [
2368 + 'key' => $key,
2369 + 'label' => Arr::get($definition, 'label', $key),
2370 + 'note' => $this->getAppearanceFieldNote($definition),
2371 + 'default' => (string)Arr::get($definition, 'default', ''),
2372 + ];
2373 + }
2374 +
2375 + $groups[] = [
2376 + 'key' => $groupKey,
2377 + 'label' => $groupLabel,
2378 + 'fields' => $fields,
2379 + ];
2380 + }
2381 +
2382 + return $groups;
2383 + }
2384 +
2385 + /**
2386 + * The border-radius controls, as data the appearance component renders
2387 + * its number inputs from.
2388 + *
2389 + * Driven off RadiusPalette::roles(), the same registry the sanitiser and
2390 + * the storefront CSS read, so a control can never write a role the page
2391 + * would not print.
2392 + *
2393 + * @return array
2394 + */
2395 + protected function getAppearanceRadiusSection(): array
2396 + {
2397 + $fields = [];
2398 +
2399 + foreach (RadiusPalette::roles() as $key => $definition) {
2400 + $fields[] = [
2401 + 'key' => $key,
2402 + 'label' => (string)Arr::get($definition, 'label', $key),
2403 + 'note' => (string)Arr::get($definition, 'note', ''),
2404 + ];
2405 + }
2406 +
2407 + return [
2408 + 'label' => __('Border radius', 'fluent-cart'),
2409 + 'note' => __('A number is read as pixels, or add a unit: 8, 8px, 0.5rem, 1em. Leave a field empty to keep FluentCart\'s default.', 'fluent-cart'),
2410 + 'invalid' => __('Use a number, optionally with px, rem or em.', 'fluent-cart'),
2411 + 'fields' => $fields,
2412 + ];
2413 + }
2414 +
2415 + /**
2416 + * The hint under one colour picker: what it drives, and the value it
2417 + * falls back to when left empty.
2418 + *
2419 + * @param array $definition
2420 + * @return string
2421 + */
2422 + protected function getAppearanceFieldNote(array $definition): string
2423 + {
2424 + $usage = (string)Arr::get($definition, 'note', '');
2425 + $default = (string)Arr::get($definition, 'default', '');
2426 +
2427 + if ($default === '') {
2428 + return $usage;
2429 + }
2430 +
2431 + if ($usage === '') {
2432 + /* translators: %1$s: the hex colour FluentCart falls back to */
2433 + return sprintf(__('Default: %1$s', 'fluent-cart'), $default);
2434 + }
2435 +
2436 + /* translators: 1: what the colour is used for, 2: the hex colour FluentCart falls back to */
2437 + return sprintf(__('%1$s Default: %2$s', 'fluent-cart'), $usage, $default);
1714 2438 }
1715 2439
1716 2440 /**
1717 2441 * Get theme colors as CSS variable string.