diff --git a/CHANGELOG.md b/CHANGELOG.md index d19020766..e7ea536c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,8 +17,9 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a - `src/Exception/MissingFilterInfoException.php` because it is not used anymore. ### Added -- New `Caching` service for manifest data. +- New `Caching` service for manifest data and new options to flush cache from the settings. - Input number validation for allowed keys. +- WP Rocket cache options settings. ### Fixed - Custom post type labels are not translatable. diff --git a/package.json b/package.json index e1ee3d017..a98e140d8 100644 --- a/package.json +++ b/package.json @@ -29,16 +29,16 @@ }, "devDependencies": { "husky": "^9.0.11", - "webpack": "^5.90.2", + "webpack": "^5.91.0", "webpack-cli": "^5.1.4" }, "dependencies": { - "@eightshift/frontend-libs": "https://github.com/infinum/eightshift-frontend-libs.git#develop", + "@eightshift/frontend-libs": "^12.0.0", "autosize": "^6.0.1", "choices.js": "^10.2.0", "dropzone": "^6.0.0-beta.2", "flatpickr": "^4.6.13", - "reactflow": "^11.10.4" + "reactflow": "^11.11.3" }, "husky": { "hooks": { diff --git a/src/AdminMenus/FormAdminMenu.php b/src/AdminMenus/FormAdminMenu.php index 67bdc88a8..d63344e29 100644 --- a/src/AdminMenus/FormAdminMenu.php +++ b/src/AdminMenus/FormAdminMenu.php @@ -319,7 +319,7 @@ protected function processAttributes($attr): array */ private function getMultilangTitle(string $title): string { - $useWpml = \apply_filters(SettingsWpml::FILTER_SETTINGS_IS_VALID_NAME, []); + $useWpml = \apply_filters(SettingsWpml::FILTER_SETTINGS_IS_VALID_NAME, false); if ($useWpml) { $lang = \apply_filters('wpml_current_language', ''); if ($lang) { diff --git a/src/Blocks/components/admin-settings/admin-settings.php b/src/Blocks/components/admin-settings/admin-settings.php index d27a6f4a9..0aa700c48 100644 --- a/src/Blocks/components/admin-settings/admin-settings.php +++ b/src/Blocks/components/admin-settings/admin-settings.php @@ -70,7 +70,6 @@ 'layout', 'layoutType' => 'layout-v-stack-clean', 'layoutContent' => [ - ...$outputIntegrations, [ - 'component' => 'divider', - 'dividerExtraVSpacing' => true, + 'component' => 'card-inline', + 'cardInlineTitle' => \__('All operational cache', 'eightshift-forms'), + 'cardInlineSubTitle' => \__('Delete all forms operational cache at once!', 'eightshift-forms'), + 'cardInlineIcon' => UtilsHelper::getUtilsIcons('allChecked'), + 'cardInlineRightContent' => [ + [ + 'component' => 'submit', + 'submitValue' => \__('Clear', 'eightshift-forms'), + 'submitVariant' => 'ghost', + 'submitAttrs' => [ + UtilsHelper::getStateAttribute('cacheType') => 'allOperational', + UtilsHelper::getStateAttribute('reload') => 'false', + ], + 'additionalClass' => UtilsHelper::getStateSelectorAdmin('cacheDelete'), + ], + ], ], - ...$outputOther, [ 'component' => 'divider', 'dividerExtraVSpacing' => true, ], [ 'component' => 'card-inline', - 'cardInlineTitle' => 'All caches', - 'cardInlineSubTitle' => 'Use with caution!', + 'cardInlineTitle' => \__('All internal cache', 'eightshift-forms'), + 'cardInlineSubTitle' => \__('Delete all forms internal cache at once!', 'eightshift-forms'), 'cardInlineIcon' => UtilsHelper::getUtilsIcons('allChecked'), 'cardInlineRightContent' => [ [ @@ -149,7 +161,7 @@ function ($key, $value) { 'submitValue' => \__('Clear', 'eightshift-forms'), 'submitVariant' => 'ghost', 'submitAttrs' => [ - UtilsHelper::getStateAttribute('cacheType') => 'all', + UtilsHelper::getStateAttribute('cacheType') => 'allInteral', UtilsHelper::getStateAttribute('reload') => 'false', ], 'additionalClass' => UtilsHelper::getStateSelectorAdmin('cacheDelete'), @@ -158,6 +170,26 @@ function ($key, $value) { ], ] ], + [ + 'component' => 'intro', + 'introTitle' => \__('Integration cache', 'eightshift-forms'), + 'introSubtitle' => \__('Here you can clear individual cache for each integration.', 'eightshift-forms'), + ], + [ + 'component' => 'layout', + 'layoutType' => 'layout-v-stack-clean', + 'layoutContent' => $outputIntegrations, + ], + [ + 'component' => 'intro', + 'introTitle' => \__('Operational cache', 'eightshift-forms'), + 'introSubtitle' => \__('Here you can clear individual operational cache.', 'eightshift-forms'), + ], + [ + 'component' => 'layout', + 'layoutType' => 'layout-v-stack-clean', + 'layoutContent' => $outputOther, + ], ]; } } diff --git a/src/Hooks/Filters.php b/src/Hooks/Filters.php index e1d974437..727ddddc5 100644 --- a/src/Hooks/Filters.php +++ b/src/Hooks/Filters.php @@ -33,6 +33,7 @@ use EightshiftForms\Integrations\Calculator\SettingsCalculator; use EightshiftForms\Integrations\Pipedrive\SettingsPipedrive; use EightshiftForms\Misc\SettingsCloudflare; +use EightshiftForms\Misc\SettingsRocketCache; use EightshiftForms\Misc\SettingsWpml; use EightshiftForms\Security\SettingsSecurity; use EightshiftFormsVendor\EightshiftFormsUtils\Config\UtilsConfig; @@ -350,6 +351,8 @@ private static function getSettingsNoneTranslatableNames(): array SettingsWpml::SETTINGS_WPML_USE_KEY, + SettingsRocketCache::SETTINGS_ROCKET_CACHE_USE_KEY, + SettingsFallback::SETTINGS_FALLBACK_USE_KEY, SettingsMigration::SETTINGS_MIGRATION_USE_KEY, diff --git a/src/Hooks/FiltersSettingsBuilder.php b/src/Hooks/FiltersSettingsBuilder.php index 2df6dd3d2..6ab731900 100644 --- a/src/Hooks/FiltersSettingsBuilder.php +++ b/src/Hooks/FiltersSettingsBuilder.php @@ -58,6 +58,7 @@ use EightshiftForms\Integrations\Pipedrive\PipedriveClient; use EightshiftForms\Integrations\Pipedrive\SettingsPipedrive; use EightshiftForms\Misc\SettingsCloudflare; +use EightshiftForms\Misc\SettingsRocketCache; use EightshiftForms\Misc\SettingsWpml; use EightshiftForms\Security\SettingsSecurity; use EightshiftForms\Validation\SettingsValidation; @@ -466,6 +467,15 @@ public function getSettingsFiltersData(): array 'desc' => \__('WPML is a WordPress plugin, which allows building and running multilingual sites. It integrates with almost all popular WordPress themes and plugins and allows building anything from multilingual blogs to complex e-commerce and corporate sites.', 'eightshift-forms'), ], ], + SettingsRocketCache::SETTINGS_TYPE_KEY => [ + 'settingsGlobal' => SettingsRocketCache::FILTER_SETTINGS_GLOBAL_NAME, + 'type' => UtilsConfig::SETTINGS_INTERNAL_TYPE_MISCELLANEOUS, + 'use' => SettingsRocketCache::SETTINGS_ROCKET_CACHE_USE_KEY, + 'labels' => [ + 'title' => \__('Rocket Cache', 'eightshift-forms'), + 'desc' => \__('WP Rocket cache is a WordPress plugin that speeds up your website by caching static content, minifying CSS and JavaScript, and optimizing images.', 'eightshift-forms'), + ], + ], SettingsCloudflare::SETTINGS_TYPE_KEY => [ 'settingsGlobal' => SettingsCloudflare::FILTER_SETTINGS_GLOBAL_NAME, 'type' => UtilsConfig::SETTINGS_INTERNAL_TYPE_MISCELLANEOUS, diff --git a/src/Misc/SettingsCloudflare.php b/src/Misc/SettingsCloudflare.php index 489a7c34b..8b608c113 100644 --- a/src/Misc/SettingsCloudflare.php +++ b/src/Misc/SettingsCloudflare.php @@ -80,7 +80,7 @@ public function getSettingsGlobalData(): array return [ UtilsSettingsOutputHelper::getIntro(self::SETTINGS_TYPE_KEY), - UtilsSettingsOutputHelper::getMiscDisclaimer(), + UtilsSettingsOutputHelper::getMiscDisclaimer(\__('Cloudflare', 'eightshift-forms')), [ 'component' => 'intro', 'introTitle' => \__('Features affected by Cloudflare are:', 'eightshift-forms'), diff --git a/src/Misc/SettingsRocketCache.php b/src/Misc/SettingsRocketCache.php new file mode 100644 index 000000000..886d1cc72 --- /dev/null +++ b/src/Misc/SettingsRocketCache.php @@ -0,0 +1,101 @@ +> + */ + public function getSettingsGlobalData(): array + { + if (!UtilsSettingsHelper::isOptionCheckboxChecked(self::SETTINGS_ROCKET_CACHE_USE_KEY, self::SETTINGS_ROCKET_CACHE_USE_KEY)) { + return UtilsSettingsOutputHelper::getNoActiveFeature(); + } + + return [ + UtilsSettingsOutputHelper::getIntro(self::SETTINGS_TYPE_KEY), + UtilsSettingsOutputHelper::getMiscDisclaimer(\__('WP Rocket Cache', 'eightshift-forms')), + [ + 'component' => 'intro', + 'introTitle' => \__('Features affected by WP Rocket cache are:', 'eightshift-forms'), + ], + [ + 'component' => 'layout', + 'layoutType' => 'layout-v-stack-card', + 'layoutContent' => [ + [ + 'component' => 'intro', + 'introTitle' => \__('Forms cache', 'eightshift-forms'), + 'introSubtitle' => \__('When you clear forms cache, you will also clear WP Rocket cache.', 'eightshift-forms'), + ], + ], + ], + ]; + } +} diff --git a/src/Misc/SettingsWpml.php b/src/Misc/SettingsWpml.php index c78919ea4..ac581e09e 100644 --- a/src/Misc/SettingsWpml.php +++ b/src/Misc/SettingsWpml.php @@ -101,7 +101,7 @@ public function getSettingsGlobalData(): array return [ UtilsSettingsOutputHelper::getIntro(self::SETTINGS_TYPE_KEY), - UtilsSettingsOutputHelper::getMiscDisclaimer(), + UtilsSettingsOutputHelper::getMiscDisclaimer(\__('WPML', 'eightshift-forms')), [ 'component' => 'intro', 'introSubtitle' => \__('In order for Eightshift Forms to work correctly with WPML, you must enable translations in the WPML settings.', 'eightshift-forms'), diff --git a/src/Rest/Routes/Settings/CacheDeleteRoute.php b/src/Rest/Routes/Settings/CacheDeleteRoute.php index ecbdca9e1..c6ca01c4a 100644 --- a/src/Rest/Routes/Settings/CacheDeleteRoute.php +++ b/src/Rest/Routes/Settings/CacheDeleteRoute.php @@ -10,10 +10,12 @@ namespace EightshiftForms\Rest\Routes\Settings; +use EightshiftForms\Misc\SettingsRocketCache; use EightshiftFormsVendor\EightshiftFormsUtils\Helpers\UtilsApiHelper; use EightshiftForms\Validation\ValidatorInterface; use EightshiftFormsVendor\EightshiftFormsUtils\Config\UtilsConfig; use EightshiftFormsVendor\EightshiftFormsUtils\Rest\Routes\AbstractUtilsBaseRoute; +use EightshiftFormsVendor\EightshiftLibs\Cache\ManifestCacheInterface; use EightshiftFormsVendor\EightshiftLibs\Helpers\Helpers; use WP_REST_Request; @@ -29,15 +31,25 @@ class CacheDeleteRoute extends AbstractUtilsBaseRoute */ protected $validator; + /** + * Instance variable for listing data. + * + * @var ManifestCacheInterface + */ + protected $manifestCache; + /** * Create a new instance that injects classes * * @param ValidatorInterface $validator Inject validation methods. + * @param ManifestCacheInterface $manifestCache Inject manifest cache interface. */ public function __construct( - ValidatorInterface $validator + ValidatorInterface $validator, + ManifestCacheInterface $manifestCache ) { $this->validator = $validator; + $this->manifestCache = $manifestCache; } /** @@ -90,40 +102,51 @@ public function routeCallback(WP_REST_Request $request) $data = \apply_filters(UtilsConfig::FILTER_SETTINGS_DATA, []); - if ($type === 'all') { - $allItems = Helpers::flattenArray(\array_map( - static function ($item) { - if (isset($item['cache'])) { - return $item['cache']; + switch ($type) { + case 'allOperational': + $allItems = Helpers::flattenArray(\array_map( + static function ($item) { + if (isset($item['cache'])) { + return $item['cache']; + } + }, + $data + )); + + if ($allItems) { + foreach ($allItems as $item) { + \delete_transient($item); } - }, - $data - )); + } + + $outputTitle = \esc_html__('All operational', 'eightshift-forms'); + break; + case 'allInteral': + $outputTitle = \esc_html__('All internal', 'eightshift-forms'); + $this->manifestCache->deleteAllCache(); + break; + default: + $cacheTypes = $data[$type]['cache'] ?? []; + if (!$cacheTypes) { + return \rest_ensure_response( + UtilsApiHelper::getApiErrorPublicOutput( + \esc_html__('Provided cache type doesn\'t exist.', 'eightshift-forms'), + [], + $debug + ) + ); + } - if ($allItems) { - foreach ($allItems as $item) { + foreach ($cacheTypes as $item) { \delete_transient($item); } - } - } else { - $cacheTypes = $data[$type]['cache'] ?? []; - if (!$cacheTypes) { - return \rest_ensure_response( - UtilsApiHelper::getApiErrorPublicOutput( - \esc_html__('Provided cache type doesn\'t exist.', 'eightshift-forms'), - [], - $debug - ) - ); - } - - foreach ($cacheTypes as $item) { - \delete_transient($item); - } + + $outputTitle = \ucfirst($type); + break; } // Clear WP-Rocket cache if cache is cleared. - if (\function_exists('rocket_clean_domain')) { + if (\function_exists('rocket_clean_domain') && \apply_filters(SettingsRocketCache::FILTER_SETTINGS_IS_VALID_NAME, false)) { \rocket_clean_domain(); } @@ -131,7 +154,7 @@ static function ($item) { return \rest_ensure_response( UtilsApiHelper::getApiSuccessPublicOutput( // translators: %s will be replaced with the form type. - \sprintf(\esc_html__('%s cache deleted successfully!', 'eightshift-forms'), \ucfirst($type)), + \sprintf(\esc_html__('%s cache deleted successfully!', 'eightshift-forms'), $outputTitle), [], $debug )