From 1fda32337400d932461ca7bf0047638a87b7360b Mon Sep 17 00:00:00 2001
From: balexey88
Date: Fri, 18 Oct 2024 00:08:37 +0300
Subject: [PATCH 1/4] Prepare release 4.1.2
---
changelog.txt | 9 +
changes.md | 10 +
composer.lock | 74 +--
lib/classes/class-bootstrap.php | 31 +-
lib/classes/class-module.php | 20 -
lib/classes/class-settings.php | 1 +
.../compatibility/easy-digital-downloads.php | 145 ------
.../compatibility/lite-speed-cache.php | 439 ----------------
.../siteorigin-widget-bundle.php | 196 -------
lib/classes/compatibility/wpforms.php | 490 ------------------
lib/classes/status/class-info-stateless.php | 12 +
lib/classes/status/class-info.php | 26 +
readme.md | 4 +
readme.txt | 15 +-
static/data/addons.php | 40 ++
static/scripts/wp-stateless-batch.js | 2 +-
static/scripts/wp-stateless-settings.js | 36 ++
static/scripts/wp-stateless.js | 4 +-
static/views/settings-sections/general.php | 19 +
static/views/status-sections/info.php | 8 +-
static/views/status-sections/migrations.php | 4 +-
vendor/composer/autoload_classmap.php | 4 -
vendor/composer/autoload_static.php | 4 -
vendor/composer/installed.php | 4 +-
wp-stateless-media.php | 2 +-
25 files changed, 221 insertions(+), 1378 deletions(-)
delete mode 100644 lib/classes/compatibility/easy-digital-downloads.php
delete mode 100644 lib/classes/compatibility/lite-speed-cache.php
delete mode 100644 lib/classes/compatibility/siteorigin-widget-bundle.php
delete mode 100644 lib/classes/compatibility/wpforms.php
diff --git a/changelog.txt b/changelog.txt
index 5e29832ab..a8bae309c 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,4 +1,13 @@
== Changelog ==
+= 4.1.2 =
+* ENHANCEMENT - added `REST API Endpoint` setting, which useful when WordPress dashboard and frontend website utilize different domain names.
+* ENHANCEMENT - extended `Status Info` with the information to help diagnose REST API or AJAX issues.
+* COMPATIBILITY - SiteOrigin Widgets Bundle Compatibility replaced with [WP-Stateless - SiteOrigin Widgets Bundle Addon](https://wordpress.org/plugins/wp-stateless-siteorigin-widgets-bundle-addon/).
+* COMPATIBILITY - WPForms Compatibility replaced with [WP-Stateless - WPForms Addon](https://wordpress.org/plugins/wp-stateless-wpforms-addon/).
+* COMPATIBILITY - Easy Digital Downloads Compatibility replaced with [WP-Stateless - Easy Digital Downloads Addon](* COMPATIBILITY - Easy Digital Downloads Compatibility replaced with [WP-Stateless - Easy Digital Downloads Addon](https://wordpress.org/plugins/wp-stateless-easy-digital-downloads-addon/).
+* COMPATIBILITY - LiteSpeed Cache Compatibility replaced with [WP-Stateless - LiteSpeed Cache Addon](https://wordpress.org/plugins/wp-stateless-litespeed-cache-addon/).
+* FIX: remove PHP warning on `Status` settings tab.
+
= 4.1.1 =
* FIX - cache issues during Data Optimization.
diff --git a/changes.md b/changes.md
index 8b252a409..81fda0799 100644
--- a/changes.md
+++ b/changes.md
@@ -1,3 +1,13 @@
+#### 4.1.2
+* ENHANCEMENT - added `REST API Endpoint` setting, which useful when WordPress dashboard and frontend website utilize different domain names.
+* ENHANCEMENT - extended `Status Info` with the information to help diagnose REST API or AJAX issues.
+* COMPATIBILITY - SiteOrigin Widgets Bundle Compatibility replaced with [WP-Stateless - SiteOrigin Widgets Bundle Addon](https://wordpress.org/plugins/wp-stateless-siteorigin-widgets-bundle-addon/).
+* COMPATIBILITY - WPForms Compatibility replaced with [WP-Stateless - WPForms Addon](https://wordpress.org/plugins/wp-stateless-wpforms-addon/).
+* COMPATIBILITY - Easy Digital Downloads Compatibility replaced with [WP-Stateless - Easy Digital Downloads Addon](https://wordpress.org/plugins/wp-stateless-easy-digital-downloads-addon/).
+* COMPATIBILITY - LiteSpeed Cache Compatibility replaced with [WP-Stateless - LiteSpeed Cache Addon](https://wordpress.org/plugins/wp-stateless-litespeed-cache-addon/).
+* FIX: PHP warning on `Status` settings tab.
+
+
#### 4.1.1
* FIX - cache issues during Data Optimization.
diff --git a/composer.lock b/composer.lock
index 72c191228..8255db5c6 100644
--- a/composer.lock
+++ b/composer.lock
@@ -264,15 +264,15 @@
},
{
"name": "udx/lib-ud-api-client",
- "version": "1.2.1",
+ "version": "1.2.4",
"source": {
"type": "git",
"url": "git@github.com:udx/lib-ud-api-client",
- "reference": "1.2.1"
+ "reference": "1.2.4"
},
"dist": {
"type": "zip",
- "url": "https://github.com/udx/lib-ud-api-client/archive/1.2.1.zip"
+ "url": "https://github.com/udx/lib-ud-api-client/archive/1.2.4.zip"
},
"require": {
"php": ">=5.3"
@@ -305,80 +305,20 @@
"wordpress"
]
},
- {
- "name": "udx/lib-utility",
- "version": "0.4.0",
- "source": {
- "type": "git",
- "url": "git@github.com:udx/lib-utility",
- "reference": "0.4.0"
- },
- "dist": {
- "type": "zip",
- "url": "https://github.com/udx/lib-utility/archive/0.4.0.zip"
- },
- "require-dev": {
- "phpunit/phpunit": "4.1.*"
- },
- "type": "library",
- "extra": {
- "installer-name": "lib-utility",
- "component": {
- "name": "utility",
- "scripts": [
- "scripts/*.js"
- ]
- }
- },
- "autoload": {
- "classmap": [
- "lib"
- ]
- },
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Andy Potanin",
- "email": "andy.potanin@usabilitydynamics.com",
- "homepage": "https://www.usabilitydynamics.com",
- "role": "Developer"
- },
- {
- "name": "Maxim Peshkov",
- "email": "maxim.peshkov@usabilitydynamics.com",
- "homepage": "https://www.usabilitydynamics.com",
- "role": "Developer"
- },
- {
- "name": "Anton Korotkov",
- "email": "anton.korotkov@usabilitydynamics.com",
- "homepage": "https://www.usabilitydynamics.com",
- "role": "Developer"
- }
- ],
- "keywords": [
- "job",
- "process",
- "utility"
- ]
- },
{
"name": "udx/lib-wp-bootstrap",
- "version": "1.3.0",
+ "version": "1.3.3",
"source": {
"type": "git",
"url": "git@github.com:udx/lib-wp-bootstrap",
- "reference": "1.3.0"
+ "reference": "1.3.3"
},
"dist": {
"type": "zip",
- "url": "https://github.com/udx/lib-wp-bootstrap/archive/1.3.0.zip"
+ "url": "https://github.com/udx/lib-wp-bootstrap/archive/1.3.3.zip"
},
"require": {
- "php": ">=5.3",
- "udx/lib-utility": "~0.3"
+ "php": ">=5.3"
},
"type": "library",
"extra": {
diff --git a/lib/classes/class-bootstrap.php b/lib/classes/class-bootstrap.php
index cdb8ad5aa..12d33208b 100644
--- a/lib/classes/class-bootstrap.php
+++ b/lib/classes/class-bootstrap.php
@@ -140,6 +140,9 @@ public function init() {
// Register meta boxes and fields for media modal page
add_filter('attachment_fields_to_edit', array($this, 'attachment_modal_meta_box_callback'), 11, 2);
+ // Get the REST API root
+ add_filter('wp_stateless_rest_api_root', array($this, 'get_rest_api_root'));
+
/**
* Init hook
*/
@@ -1265,7 +1268,12 @@ public function admin_init() {
wp_localize_script('wp-stateless', 'stateless_l10n', $this->get_l10n_data());
wp_localize_script('wp-stateless', 'wp_stateless_configs', array(
'WP_DEBUG' => defined('WP_DEBUG') ? WP_DEBUG : false,
- 'REST_API_TOKEN' => Utility::generate_jwt_token(['user_id' => get_current_user_id()], DAY_IN_SECONDS)
+ 'REST_API_TOKEN' => Utility::generate_jwt_token(['user_id' => get_current_user_id()], DAY_IN_SECONDS),
+ 'api_root' => apply_filters( 'wp_stateless_rest_api_root', '' ),
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
+ 'stateless_check_ajax_nonce' => wp_create_nonce('stateless_check_ajax'),
+ 'text_ok' => __('Ok', ud_get_stateless_media()->domain),
+ 'text_fail' => __('Fail', ud_get_stateless_media()->domain),
));
$settings = ud_get_stateless_media()->get('sm');
@@ -1282,6 +1290,7 @@ public function admin_init() {
wp_localize_script('wp-stateless-batch', 'wp_stateless_batch', array(
'REST_API_TOKEN' => Utility::generate_jwt_token(['user_id' => get_current_user_id()], DAY_IN_SECONDS),
'is_running' => BatchTaskManager::instance()->is_running(),
+ 'api_root' => apply_filters( 'wp_stateless_rest_api_root', '' ),
));
}
@@ -2079,6 +2088,26 @@ public function is_mode($mode) {
public function get_default_cache_control() {
return Settings::DEFAULT_CACHE_CONTROL;
}
+
+ /**
+ * Override REST API root for headless CMS
+ *
+ * @return string
+ */
+ public function get_rest_api_root($rest_api_root) {
+ $rest_api_root = sanitize_url( get_rest_url() );
+ $rest_api_root .= 'wp-stateless/v1/';
+
+ if ( $this->get('sm.use_api_siteurl') == 'WP_SITEURL' ) {
+ $home = get_home_url();
+ $site = get_site_url();
+
+ return str_replace( $home, $site, $rest_api_root );
+ }
+
+
+ return $rest_api_root;
+ }
}
}
}
diff --git a/lib/classes/class-module.php b/lib/classes/class-module.php
index d7d67c7c5..72e4876df 100644
--- a/lib/classes/class-module.php
+++ b/lib/classes/class-module.php
@@ -30,11 +30,6 @@ public function __construct() {
*/
new BuddyPress();
- /**
- * Support for Easy Digital Downloads
- */
- new EDDDownloadMethod();
-
/**
* Support for Ewww Image Optimizer
*/
@@ -50,11 +45,6 @@ public function __construct() {
*/
new LearnDash();
- /**
- * Support for LiteSpeed Cache
- */
- new LSCacheWP();
-
/**
* Support for Polylang Pro
*/
@@ -70,11 +60,6 @@ public function __construct() {
*/
new SimpleLocalAvatars();
- /**
- * Support for SiteOrigin Widgets Bundle
- */
- new SOWidgetCSS();
-
/**
* Support for The Events Calendar
*/
@@ -90,11 +75,6 @@ public function __construct() {
*/
new WPBakeryPageBuilder();
- /**
- * Support for WPForms
- */
- new WPForms();
-
/**
* Support for Smush
*/
diff --git a/lib/classes/class-settings.php b/lib/classes/class-settings.php
index 2cc827129..44dcf0786 100644
--- a/lib/classes/class-settings.php
+++ b/lib/classes/class-settings.php
@@ -56,6 +56,7 @@ final class Settings extends \UDX\Settings {
'status_email_type' => array('', 'true'),
'status_email_address' => array('', ''),
'use_postmeta' => array('WP_STATELESS_POSTMETA', ['false', '']),
+ 'use_api_siteurl' => array('WP_STATELESS_API_SITEURL', ['WP_HOME', '']),
);
private $network_only_settings = array(
diff --git a/lib/classes/compatibility/easy-digital-downloads.php b/lib/classes/compatibility/easy-digital-downloads.php
deleted file mode 100644
index 70ce47c03..000000000
--- a/lib/classes/compatibility/easy-digital-downloads.php
+++ /dev/null
@@ -1,145 +0,0 @@
-get_gs_host())) {
- try {
- $file_extension = edd_get_file_extension($requested_file);
- $ctype = edd_get_file_ctype($file_extension);
-
- header("Content-Type: $ctype");
- header("Content-Transfer-Encoding: Binary");
- header("Content-Description: File Transfer");
- header("Content-disposition: attachment; filename=\"" . apply_filters('edd_requested_file_name', basename($requested_file)) . "\"");
- readfile($requested_file);
- exit;
- } catch (Exception $e) {
- if (wp_redirect($requested_file)) {
- exit;
- }
- }
- }
- }
-
- /**
- * EDD Front-end Submission Author Avatar
- *
- * @param $url
- * @param $ID
- * @return string
- */
- public function wp_get_attachment_url($url, $ID) {
- global $wp_current_filter;
-
- // Verifying that the wp_get_attachment_url is called from EDD Front-end Submission.
- // The flow of function call
- // save_form_frontend() > save_field_values() > save_field() >
- // save_field_frontend() > fes_update_avatar() > wp_get_image_editor()
- if (in_array('wp_ajax_fes_submit_profile_form', $wp_current_filter)) {
- $uploads = wp_get_upload_dir();
- $meta_data = wp_get_attachment_metadata($ID);
-
- if (!empty($meta_data['file']) && false === $uploads['error']) {
- $absolutePath = $uploads['basedir'] . "/" . $meta_data['file'];
-
- if (!file_exists($absolutePath)) {
- $this->client = ud_get_stateless_media()->get_client();
- if ($this->client && !is_wp_error($this->client)) {
- $this->client->get_media($meta_data['file'], true, $absolutePath);
- }
- }
-
- if (file_exists($absolutePath)) {
- $url = $uploads['baseurl'] . "/" . $meta_data['file'];
- }
- }
- }
- return $url;
- }
-
- /**
- * Change Upload BaseURL when called from fes_get_attachment_id_from_url function.
- * Unless fes_get_attachment_id_from_url function won't be able to return attachment id.
- * @param $data
- * @return mixed
- */
- public function upload_dir($data) {
- if ($this->hook_from_fes()) {
- $root_dir = ud_get_stateless_media()->get('sm.root_dir');
- $root_dir = apply_filters("wp_stateless_handle_root_dir", $root_dir);
- $data['baseurl'] = ud_get_stateless_media()->get_gs_host() . '/' . $root_dir;
- }
- return $data;
- }
-
- /**
- * Determine where we hook from
- * We need to do this only for fes_get_attachment_id_from_url() function
- *
- * @return bool
- */
- private function hook_from_fes() {
- $call_stack = debug_backtrace();
- if (!empty($call_stack[5]['function']) && $call_stack[5]['function'] == 'fes_get_attachment_id_from_url') {
- return true;
- }
-
- // Extra layer of condition to be sure
- if (!empty($call_stack) && is_array($call_stack)) {
- foreach ($call_stack as $step) {
- if ($step['function'] == 'getURLsAndPATHs' && strpos($step['file'], 'wp-short-pixel')) {
- return true;
- }
- }
- }
-
- return false;
- }
- }
- }
-}
diff --git a/lib/classes/compatibility/lite-speed-cache.php b/lib/classes/compatibility/lite-speed-cache.php
deleted file mode 100644
index ebddc750f..000000000
--- a/lib/classes/compatibility/lite-speed-cache.php
+++ /dev/null
@@ -1,439 +0,0 @@
-= 4.0.0
- if ( function_exists('ud_stateless_db') ) {
- $cloud_meta = [
- 'fileMd5' => apply_filters('wp_stateless_get_file_meta_value', [], $attachment_id, 'fileMd5', []),
- ];
- } else {
- $cloud_meta = get_post_meta($attachment_id, 'sm_cloud', true);
- }
-
- return $cloud_meta;
- }
-
- /**
- * Update the md5_file hash in cloud meta.
- *
- * @param int $attachment_id
- * @param array $cloud_meta
- */
- private function _update_md5_meta($attachment_id, $cloud_meta) {
- // If WP-Stateless version >= 4.0.0, postmeta can be limited to 'fileMd5' only
- // and we should not override it
- $test_meta = $cloud_meta;
- unset($test_meta['fileMd5']);
-
- if ( empty($test_meta) ) {
- $test_meta = get_post_meta($attachment_id, 'sm_cloud', true);
- $test_meta['fileMd5'] = $cloud_meta['fileMd5'];
- $cloud_meta = $test_meta;
- }
-
- update_post_meta($attachment_id, 'sm_cloud', $cloud_meta);
-
- // If WP-Stateless version >= 4.0.0
- do_action('wp_stateless_set_file_meta', $attachment_id, 'fileMd5', $cloud_meta['fileMd5']);
- }
-
- /**
- * Sync the image when Lite Speed plugin pull the optimized image.
- * We need to overwrite the existing image.
- * @param stdClass Object $row_img
- * stdClass Object
- * (
- * [id] => 28
- * [post_id] => 494
- * [optm_status] => notified
- * [src] => 2019/10/22645b39-asdf.jpg
- * [srcpath_md5] => ad206986974729e1c8edc9321ed9ba9b
- * [src_md5] => 9d396b4f7a261a5fac1234b292a7d585
- * [root_id] => 0
- * [src_filesize] => 1
- * [target_filesize] => 0
- * [target_saved] => 827956
- * [webp_filesize] => 0
- * [webp_saved] => 830743
- * [server_info] => {
- * "server":"https:\/\/us1.wp.api.litespeedtech.com",
- * "id":"SEU98",
- * "ori_md5":"3a7bb6b684d34552d75291ed4c32d399",
- * "ori":"https:\/\/us1.wp.api.litespeedtech.com\/dl\/20191011\/c91821\/47721644.jpg",
- * "webp_md5":"61d80e1d2799af383c820492a1208846",
- * "webp":"https:\/\/us1.wp.api.litespeedtech.com\/dl\/20191011\/c91821\/47721644.jpg.webp"
- * }
- * )
- *
- * @param String $local_file
- * /var/www/wp-content/uploads/2019/10/22645b39-asdf.jpg
- *
- */
- public function sync_image($row_img, $local_file) {
- $rm_ori_bkup = apply_filters('litespeed_conf', 'img_optm-rm_bkup');
- $gs_name = apply_filters('wp_stateless_file_name', $row_img->src);
- $cloud_meta = $this->_get_md5_meta($row_img->post_id);
-
- if (empty($cloud_meta)) $cloud_meta = array();
-
- if (!$rm_ori_bkup) {
- $extension = pathinfo($gs_name, PATHINFO_EXTENSION);
- $bk_file = substr($gs_name, 0, -strlen($extension)) . 'bk.' . $extension;
- $cloud_meta['fileMd5'][$bk_file] = $cloud_meta['fileMd5'][$gs_name];
- do_action('sm:sync::copyFile', $gs_name, $bk_file);
- }
-
- $cloud_meta['fileMd5'][$gs_name] = md5_file($local_file);
- $this->_update_md5_meta($row_img->post_id, $cloud_meta);
- do_action('sm:sync::syncFile', $gs_name, $local_file, 2);
- }
-
- /**
- * Upload webp image after LS pulled the images.
- * @todo put md5_file hash creating here. $row_img might have attachment_id
- * @param $row_img
- * @param $local_file
- */
- public function sync_webp($row_img, $local_file) {
- $optm_webp = apply_filters('litespeed_conf', 'img_optm-webp');
- if ($optm_webp) {
- $gs_name = apply_filters('wp_stateless_file_name', $row_img->src . '.webp');
-
- $cloud_meta = $this->_get_md5_meta($row_img->post_id);
- $cloud_meta['fileMd5'][$gs_name] = md5_file($local_file);
- $this->_update_md5_meta($row_img->post_id, $cloud_meta);
-
- add_filter('upload_mimes', array($this, 'add_webp_mime'), 10, 2);
- do_action('sm:sync::syncFile', $gs_name, $local_file, 2, array('use_root' => true));
- }
- }
-
- /**
- * Bypassing the is_internal_file check on LiteSpeed Cache.
- * That check fails because we are replacing URL with GCS URL.
- * So we need to override it with filter.
- *
- * @todo maybe we can add some validation.
- *
- * @param $return
- * @param $url
- * @return bool
- */
- public function litespeed_media_check_img($return, $url) {
- $image_host = ud_get_stateless_media()->get_gs_host();
- if (strpos($url, $image_host) === 0) {
- return true;
- }
- return $return;
- }
-
- /**
- * Return information about a file from relative path.
- *
- * @param $info
- * @param $short_file_path
- * @param $post_id
- * @return array( 'url', 'md5', 'size' )
- */
- public function litespeed_media_info($info, $short_file_path, $post_id) {
- if (!$post_id) return $info;
-
- try {
- $metadata = wp_get_attachment_metadata($post_id);
- $cloud_meta = $this->_get_md5_meta($post_id);
-
- if (!empty($metadata['gs_link'])) {
- $short_file_path = apply_filters('wp_stateless_file_name', $short_file_path);
- $url = ud_get_stateless_media()->get_gs_host() . '/' . $short_file_path;
- $md5 = !empty($cloud_meta['fileMd5'][$short_file_path]) ? $cloud_meta['fileMd5'][$short_file_path] : null;
-
- if ($metadata['file'] == $short_file_path) {
- $url = $metadata['gs_link'];
- } else {
- foreach ($metadata['sizes'] as $size => $meta) {
- if ($meta['file'] == basename($short_file_path)) {
- $url = $meta['gs_link'];
- break;
- }
- }
- }
-
- if ($md5) {
- $info = array('url' => $url, 'md5' => $md5, 'size' => 1,);
- }
- }
- } catch (\Throwable $th) {
- error_log(print_r($th, true));
- }
-
- return $info;
- }
-
-
- /**
- * Deletes a file in GCS and remove the hash from cloud meta.
-
- * @param $short_file_path
- * @param $post_id
- */
- public function litespeed_media_del($short_file_path, $post_id) {
- $short_file_path = apply_filters('wp_stateless_file_name', $short_file_path);
- do_action('sm:sync::deleteFile', $short_file_path);
- }
-
- /**
- * Hooks into the rename function of the LS cache.
- * And move the file in GCS.
- * Also update the md5_file hash on cloud meta.
- *
- * @param $short_file_path
- * @param $short_file_path_new
- * @param $post_id
- */
- public function litespeed_media_rename($short_file_path, $short_file_path_new, $post_id) {
- $short_file_path = apply_filters('wp_stateless_file_name', $short_file_path);
- $short_file_path_new = apply_filters('wp_stateless_file_name', $short_file_path_new);
-
- // copy file to the new location and delete the old one.
- do_action('sm:sync::moveFile', $short_file_path, $short_file_path_new);
-
- $this->update_hash($post_id, $short_file_path_new, $short_file_path);
- }
-
- /**
- * add_webp_mime
- * @param $t
- * @param $user
- * @return mixed
- */
- public function add_webp_mime($t, $user) {
- $t['webp'] = 'image/webp';
- return $t;
- }
-
- /**
- * Move file hash from one key to another.
- *
- * @param $attachment_id
- * @param $gs_name_new key to store md5_file.
- * @param $gs_name_old whether to get md5 from another entry.
- * @param bool $delete whether only remove the key.
- * @return bool
- */
- public function update_hash($attachment_id, $gs_name_new, $gs_name_old, $delete = false) {
- try {
- $cloud_meta = $this->_get_md5_meta($attachment_id);
-
- if (!$delete) {
- if ($gs_name_old && !empty($cloud_meta['fileMd5'][$gs_name_old])) {
- $cloud_meta['fileMd5'][$gs_name_new] = $cloud_meta['fileMd5'][$gs_name_old];
- } else {
- $url = ud_get_stateless_media()->get_gs_host() . '/' . $gs_name_new;
- $cloud_meta['fileMd5'][$gs_name_new] = md5_file($url);
- }
- }
-
- if (isset($cloud_meta['fileMd5'][$gs_name_old])) unset($cloud_meta['fileMd5'][$gs_name_old]);
-
- $this->_update_md5_meta($attachment_id, $cloud_meta);
-
- return true;
- } catch (\Throwable $th) {
- error_log(print_r($th, true));
- return false;
- }
- return false;
- }
-
- /**
- * Adds file hash to cloud meta, so that we can use it later.
- *
- * @param $cloud_meta
- * @param $media
- * @param $image_size
- * @param $img
- * @param $bucketLink
- * @return array $cloud_meta with fileMd5
- */
- public function cloud_meta_add_file_md5($cloud_meta, $media, $image_size, $img, $bucketLink) {
- if ($file_hash = md5_file($img['path'])) {
- $gs_name = !empty($media['name']) ? $media['name'] : $img['gs_name'];
-
- // Storing file hash
- $cloud_meta['fileMd5'][$gs_name] = $file_hash;
-
- // If WP-Stateless version >= 4.0.0
- if ( function_exists('ud_stateless_db') ) {
- $metadata = $media['metadata'] ?? [];
-
- $post_id = null;
-
- if ( isset($metadata['object-id']) ) {
- $post_id = $metadata['object-id'];
- } else if ( isset($metadata['child-of']) ) {
- $post_id = $metadata['child-of'];
- }
-
- $meta = apply_filters('wp_stateless_get_file_meta_value', [], $post_id, 'fileMd5', []);
- $meta[$gs_name] = $file_hash;
-
- do_action('wp_stateless_set_file_meta', $post_id, 'fileMd5', $meta);
- }
- }
-
- return $cloud_meta;
- }
-
- /**
- * On manual sync/regenerate we need to sync backup/webp files.
- *
- * @param $attachment_id
- * @param $metadata
- */
- public function manual_sync_backup_file($attachment_id, $metadata) {
- $cloud_meta = $this->_get_md5_meta($attachment_id);
-
- if (!empty($cloud_meta['fileMd5'])) {
- $upload_dir = wp_upload_dir();
- $fileMd5 = $cloud_meta['fileMd5'];
- $root_dir = ud_get_stateless_media()->get('sm.root_dir');
- $root_dir = apply_filters("wp_stateless_handle_root_dir", $root_dir);
- $root_dir = trim($root_dir, '/ '); // Remove any forward slash and empty space.
-
- foreach ($fileMd5 as $gs_name => $value) {
- $_gs_name = str_replace($root_dir, '', $gs_name);
- $local_file = $upload_dir['basedir'] . '/' . trim($_gs_name, '/');
-
- do_action('sm:sync::syncFile', $gs_name, $local_file, true);
- }
- }
- }
-
- /**
- * On manual sync/regenerate wp regenerate all image sizes.
- * So to keep the file md5 accurate we need to update it after image is regenerated.
- *
- * Manual sync if it's the first time syncing and image optimized before enabling Stateless
- *
- * @param $attachment_id
- */
- public function update_md5_and_manual_sync($attachment_id) {
- $cloud_meta = $this->_get_md5_meta($attachment_id);
-
- $metadata = wp_get_attachment_metadata($attachment_id);
- $image_sizes = Utility::get_path_and_url($metadata, $attachment_id);
-
- if (!empty($cloud_meta['fileMd5'])) {
- foreach ($image_sizes as $img) {
- $cloud_meta['fileMd5'][$img['gs_name']] = md5_file($img['path']);
- }
- }
-
- if (empty($cloud_meta['fileMd5']) || count($cloud_meta['fileMd5']) <= 1) {
- if (empty($cloud_meta)) {
- $cloud_meta = array();
- }
-
- // In case image optimized before enabling Stateless.
- // We only need to copy from local to GCS, otherwise file_md5 meta should be available.
- foreach ($image_sizes as $img) {
- $file_path = $img['path'];
- $rm_ori_bkup = apply_filters('litespeed_conf', 'img_optm-rm_bkup');
- $optm_webp = apply_filters('litespeed_conf', 'img_optm-webp');
-
- if (!$rm_ori_bkup) {
- $extension = pathinfo($file_path, PATHINFO_EXTENSION);
- $bk_file = substr($file_path, 0, -strlen($extension)) . 'bk.' . $extension;
- $bk_file_optm = substr($file_path, 0, -strlen($extension)) . 'bk.optm.' . $extension;
- if (file_exists($bk_file)) {
- $gs_name = apply_filters('wp_stateless_file_name', $bk_file);
- $cloud_meta['fileMd5'][$gs_name] = md5_file($bk_file);
- do_action('sm:sync::syncFile', $gs_name, $bk_file);
- } elseif (file_exists($bk_file_optm)) {
- $gs_name = apply_filters('wp_stateless_file_name', $bk_file_optm);
- $cloud_meta['fileMd5'][$gs_name] = md5_file($bk_file_optm);
- do_action('sm:sync::syncFile', $gs_name, $bk_file_optm);
- }
- }
-
- if ($optm_webp) {
- $gs_name_webp = $file_path . '.webp';
- $gs_name_webp_optm = $file_path . '.optm.webp';
- if (file_exists($gs_name_webp)) {
- $gs_name = apply_filters('wp_stateless_file_name', $gs_name_webp);
- $cloud_meta['fileMd5'][$gs_name] = md5_file($gs_name_webp);
- do_action('sm:sync::syncFile', $gs_name, $gs_name_webp);
- } elseif (file_exists($gs_name_webp_optm)) {
- $gs_name = apply_filters('wp_stateless_file_name', $gs_name_webp_optm);
- $cloud_meta['fileMd5'][$gs_name] = md5_file($gs_name_webp_optm);
- do_action('sm:sync::syncFile', $gs_name, $gs_name_webp_optm);
- }
- }
- }
- }
-
- $this->_update_md5_meta($attachment_id, $cloud_meta);
- }
- }
- }
-}
diff --git a/lib/classes/compatibility/siteorigin-widget-bundle.php b/lib/classes/compatibility/siteorigin-widget-bundle.php
deleted file mode 100644
index 9857922b7..000000000
--- a/lib/classes/compatibility/siteorigin-widget-bundle.php
+++ /dev/null
@@ -1,196 +0,0 @@
-filesystem = new \WP_Filesystem_Direct( false );
-
- add_filter('set_url_scheme', array($this, 'set_url_scheme'), 20);
- add_filter('pre_set_transient_sow:cleared', array($this, 'clear_file_cache'), 20, 3);
- add_filter('siteorigin_widgets_stylesheet_cleared', array($this, 'widgets_stylesheet_cleared'), 20);
- add_filter('stateless_skip_cache_busting', array($this, 'skip_cache_busting'), 10, 2);
- add_filter('sm:sync::syncArgs', array($this, 'sync_args'), 10, 4);
-
- add_action('siteorigin_widgets_stylesheet_added', array($this, 'widgets_stylesheet_added'), 10, 2);
- add_action('siteorigin_widgets_stylesheet_deleted', array($this, 'delete_file'), 10, 1);
-
- do_action('sm:sync::register_dir', '/' . self::STORAGE_PATH);
- }
-
- /**
- * In Stateless mode move file to proper location.
- */
- protected function possibly_move_file($name, $destination) {
- if ( !ud_get_stateless_media()->is_mode('stateless') ) {
- return;
- }
-
- $upload_dir = wp_upload_dir();
- $source = $upload_dir['basedir'] . '/' . $name;
-
- $this->filesystem->move( $source, $destination, true );
- }
-
- /**
- * Change URL for loading CSS files in Stateless Mode.
- *
- * @param $url
- * @return string
- */
- public function set_url_scheme($url) {
- if ( ud_get_stateless_media()->is_mode( ['disabled', 'backup'] ) ) {
- return $url;
- }
-
- $position = strpos($url, self::STORAGE_PATH);
-
- if ($position !== false) {
- $name = substr($url, $position);
- $name = apply_filters('wp_stateless_addon_files_root', '') . '/' . $name;
- $url = str_replace( ud_get_stateless_media()->get_gs_path(), ud_get_stateless_media()->get_gs_host(), $name );
-
- if ( ud_get_stateless_media()->is_mode('stateless') ) {
- $url = str_replace( ud_get_stateless_media()->get_gs_path(), ud_get_stateless_media()->get_gs_host(), $name );
- } else {
- $upload_dir = wp_upload_dir();
- $url = str_replace( $upload_dir['basedir'], ud_get_stateless_media()->get_gs_host(), $name );
- }
- }
-
- return $url;
- }
-
- /**
- * Sync new CSS file to GCS
- *
- * @param $url
- * @param $instance
- * @return string
- */
- public function widgets_stylesheet_added($name, $instance) {
- $name = self::STORAGE_PATH . $name;
- $absolutePath = apply_filters('wp_stateless_addon_files_root', '');
- $absolutePath .= '/' . $name;
-
- $name = apply_filters('wp_stateless_file_name', $name, 0);
-
- $this->possibly_move_file($name, $absolutePath);
-
- do_action('sm:sync::syncFile', $name, $absolutePath);
- }
-
- /**
- * Clear all SO CSS files from GCS after expired. 7 days
- * @param $value
- * @param $expiration
- * @param $transient
- * @return mixed
- */
- public function clear_file_cache($value, $expiration, $transient) {
- do_action('sm:sync::deleteFiles', self::STORAGE_PATH);
- return $value;
- }
-
- /**
- * Clear all SO CSS files from GCS after expired. 7 days
- */
- public function widgets_stylesheet_cleared() {
- do_action('sm:sync::deleteFiles', self::STORAGE_PATH);
- }
-
- /**
- * Remove single file from GCS. File can be without extension.
- *
- * @param $css_name
- */
- public function delete_file($css_name) {
- $extension = pathinfo($css_name, PATHINFO_EXTENSION);
-
- if ( $extension !== 'css' ) {
- $css_name .= '.css';
- }
-
- $file = self::STORAGE_PATH . $css_name;
-
- do_action('sm:sync::deleteFile', $file);
- }
-
- /**
- * Skip cache busting while activating/deactivating SO widget.
- *
- * @param $return
- * @param $filename
- * @return mixed
- */
- public function skip_cache_busting($return, $filename) {
- $back_trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
-
- foreach ($back_trace as $trace) {
- if ( isset($trace['file']) && strpos($trace['file'], 'so-widgets-bundle') !== false ) {
- if ( isset($trace['function']) && $trace['function'] === 'sanitize_file_name' ) {
- return $filename;
- }
- }
- }
-
- return $return;
- }
-
- /**
- * Update args when uploading/syncing file to GCS.
- *
- * @param array $args
- * @param string $name
- * @param string $file
- * @param bool $force
- *
- * @return array
- */
- public function sync_args($args, $name, $file, $force) {
- if ( strpos($name, self::STORAGE_PATH) !== 0 ) {
- return $args;
- }
-
- if ( ud_get_stateless_media()->is_mode('stateless') ) {
- $args['name_with_root'] = false;
- }
-
- $args['source'] = 'SiteOrigin Widgets Bundle';
- $args['source_version'] = defined('SOW_BUNDLE_VERSION') ? SOW_BUNDLE_VERSION : '';
-
- return $args;
- }
- }
- }
-}
diff --git a/lib/classes/compatibility/wpforms.php b/lib/classes/compatibility/wpforms.php
deleted file mode 100644
index 9c839366a..000000000
--- a/lib/classes/compatibility/wpforms.php
+++ /dev/null
@@ -1,490 +0,0 @@
-filesystem = new \WP_Filesystem_Direct( false );
-
- // exclude randomize_filename from wpforms page
- if ( isset( $_GET['page'] ) && $_GET['page'] == 'wpforms-builder') {
- $this->remove_cache_busting();
- }
-
- add_action( 'wp_ajax_wpforms_upload_chunk_init', [$this, 'remove_cache_busting'], 5);
- add_action( 'wp_ajax_nopriv_wpforms_upload_chunk_init', [$this, 'remove_cache_busting'], 5);
- add_action( 'wp_ajax_wpforms_submit', [$this, 'remove_cache_busting'], 5);
- add_action( 'wp_ajax_nopriv_wpforms_submit', [$this, 'remove_cache_busting'], 5);
- add_filter( 'sm:sync::syncArgs', [$this, 'sync_args'], 10, 4);
- add_filter( 'wpforms_process_after_filter', [ $this, 'upload_complete' ], 10, 3 );
- add_action( 'wpforms_process_entry_saved', [ $this, 'entry_saved' ], 10, 4 );
- add_filter( 'wpforms_entry_email_data', [ $this, 'entry_email_data' ], 10, 3 );
- add_action( 'wpforms_pre_delete_entries', [ $this, 'pre_delete_entries' ], 10, 1 );
- add_action( 'wpforms_pro_admin_entries_page_empty_trash_before', [ $this, 'before_empty_trash' ], 10, 1 );
- add_filter( 'sm:sync::nonMediaFiles', [$this, 'sync_non_media_files'], 20);
- add_action( 'wpforms_pre_delete_entry_fields', [ $this, 'pre_delete_entry_fields' ], 10, 2 );
- add_action( 'wpforms_builder_save_form', [ $this, 'builder_save_form' ], 10, 2 );
- add_action( 'admin_init', [ $this, 'show_message' ], 10, 2 );
- }
-
- /**
- * Get the position of 'so-css/' dir in the filename.
- *
- * @param $name
- * @return bool
- */
- protected function storage_position($name) {
- return strpos($name, self::STORAGE_PATH);
- }
-
- /**
- * Check if the uploaded file is in the media library.
- *
- * @return bool
- */
- protected function is_media_library($form_data, $field_id) {
- $field_data = isset( $form_data['fields'] ) && isset( $form_data['fields'][$field_id] ) ? $form_data['fields'][$field_id] : [];
-
- return isset( $field_data['media_library'] ) && !empty( $field_data['media_library'] );
- }
-
- /**
- * Skip cache busting for WPForms files.
- */
- public function remove_cache_busting() {
- remove_filter('sanitize_file_name', ['wpCloud\StatelessMedia\Utility', 'randomize_filename'], 10);
- }
-
- /**
- * Update args when uploading/syncing file to GCS.
- *
- * @param array $args
- * @param string $name
- * @param string $file
- * @param bool $force
- *
- * @return array
- */
- public function sync_args($args, $name, $file, $force) {
- if ( $this->storage_position($name) !== 0 ) {
- return $args;
- }
-
- if ( ud_get_stateless_media()->is_mode('stateless') ) {
- $args['name_with_root'] = false;
- }
-
- $args['source'] = 'WPForms';
- $args['source_version'] = defined('WPFORMS_VERSION') ? WPFORMS_VERSION : '';
-
- return $args;
- }
-
- /**
- * In Stateless mode move the file from /tmp to GCS, so thar WPForms could complete the upload.
- *
- * @param array $fields Fields data.
- * @param array $entry Submitted form entry.
- * @param array $form_data Form data and settings.
- *
- * @return array
- *
- */
- public function upload_complete($fields, $entry, $form_data) {
- if ( !ud_get_stateless_media()->is_mode('stateless') ) {
- return $fields;
- }
-
- foreach ( $fields as $field_id => $field ) {
- if ( !isset( $field['type'] ) || $field['type'] !== self::UPLOAD_FIELD_TYPE ) {
- continue;
- }
-
- // If uploads are saved to the media library
- if ( $this->is_media_library($form_data, $field_id) ) {
- continue;
- }
-
- $is_visible = ! isset( wpforms()->get( 'process' )->fields[ $field_id ]['visible'] ) || ! empty( wpforms()->get( 'process' )->fields[ $field_id ]['visible'] );
-
- if ( ! $is_visible ) {
- continue;
- }
-
- $input_name = sprintf( 'wpforms_%d_%d', absint( $form_data['id'] ), $field_id );
- $file = isset( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ] ) ? $_FILES[ $input_name ] : false;
-
- // If there was no file uploaded stop here before we continue with the upload process.
- if ( ! $file || $file['error'] !== 0 ) {
- continue;
- }
-
- $dir = apply_filters('wp_stateless_addon_sync_files_path', '', self::TMP_PATH);
- $filename = $dir . $_FILES[ $input_name ]['name'];
-
- if ( $this->filesystem->move( $_FILES[ $input_name ]['tmp_name'], $filename, true ) ) {
- $_FILES[ $input_name ]['tmp_name'] = $filename;
- }
- }
-
- return $fields;
- }
-
- /**
- * If Media Library is not used for file upload
- * - move the file to '/wpforms' dir
- * - run sync
- * - update entry data with the new file path
- */
- public function entry_saved($fields, $entry, $form_data, $entry_id) {
- $wp_uploads_dir = wp_get_upload_dir();
-
- foreach ( $fields as $field_id => $field ) {
- if ( !isset( $field['type'] ) || $field['type'] !== self::UPLOAD_FIELD_TYPE ) {
- continue;
- }
-
- if ( !isset( $field['value'] ) || empty($field['value']) ) {
- continue;
- }
-
- // If uploads are saved to the media library
- if ( $this->is_media_library($form_data, $field_id) ) {
- continue;
- }
-
- $url = $field['value'];
- $name = str_replace($wp_uploads_dir['baseurl'] . '/', '', $url);
- $absolutePath = apply_filters('wp_stateless_addon_files_root', '');
- $absolutePath .= '/' . $name;
-
- // Move file to the correct location
- if ( ud_get_stateless_media()->is_mode('stateless') ) {
- $source = str_replace( ud_get_stateless_media()->get_gs_host(), ud_get_stateless_media()->get_gs_path(), $url );
- $destination = str_replace( ud_get_stateless_media()->get_gs_host(), ud_get_stateless_media()->get_gs_path(), $absolutePath );
-
- $this->filesystem->move( $source, $destination, true );
- }
-
- // Sync non-media file
- $name = apply_filters('wp_stateless_file_name', $name, 0);
- do_action('sm:sync::syncFile', $name, $absolutePath);
-
- // Update entry data with the new file path
- if ( !ud_get_stateless_media()->is_mode( ['disabled', 'backup'] ) ) {
- $url = ud_get_stateless_media()->is_mode('stateless')
- ? str_replace( ud_get_stateless_media()->get_gs_path(), ud_get_stateless_media()->get_gs_host(), $absolutePath )
- : str_replace( $wp_uploads_dir['baseurl'], ud_get_stateless_media()->get_gs_host(), $url );
-
- global $wpdb;
-
- try {
- $entry_fields = $wpdb->get_var(
- $wpdb->prepare(
- "SELECT fields FROM {$wpdb->prefix}wpforms_entries WHERE entry_id = %d AND form_id = %d",
- $entry_id,
- $form_data['id']
- )
- );
-
- $entry_fields = json_decode($entry_fields, true);
-
- if ( isset( $entry_fields[ $field_id ] ) && isset( $entry_fields[ $field_id ]['value'] ) ) {
- $entry_fields[ $field_id ]['value'] = $url;
-
- $wpdb->update(
- $wpdb->prefix . 'wpforms_entries',
- ['fields' => json_encode($entry_fields)],
- [
- 'entry_id' => $entry_id,
- 'form_id' => $form_data['id'],
- ],
- );
- }
-
- $wpdb->update(
- $wpdb->prefix . 'wpforms_entry_fields',
- ['value' => $url],
- [
- 'entry_id' => $entry_id,
- 'field_id' => $field_id,
- 'form_id' => $form_data['id'],
- ],
- );
- } catch (\Throwable $e) {
- error_log( $e->getMessage() );
- }
-
- $fields[$field_id]['value'] = $url;
- }
- }
- }
-
- /**
- * Update email data with the new file path
- */
- public function entry_email_data($fields, $entry, $form_data) {
- if ( !ud_get_stateless_media()->is_mode('stateless') ) {
- return $fields;
- }
-
- $wp_uploads_dir = wp_get_upload_dir();
-
- foreach ( $fields as $field_id => $field ) {
- if ( !isset( $field['type'] ) || $field['type'] !== self::UPLOAD_FIELD_TYPE ) {
- continue;
- }
-
- // If uploads are saved to the media library
- if ( $this->is_media_library($form_data, $field_id) ) {
- continue;
- }
-
- $url = $field['value'];
- $name = str_replace($wp_uploads_dir['baseurl'] . '/', '', $url);
- $absolutePath = apply_filters('wp_stateless_addon_files_root', '');
- $absolutePath .= '/' . $name;
-
- $absolutePath = str_replace( ud_get_stateless_media()->get_gs_path(), ud_get_stateless_media()->get_gs_host(), $absolutePath );
-
- $fields[$field_id]['value'] = $absolutePath;
- }
-
- return $fields;
- }
-
- /**
- * Delete files from GCS when deleting entries.
- */
- public function pre_delete_entries($entry_id) {
- global $wpdb;
-
- try {
- $entry_fields = $wpdb->get_var(
- $wpdb->prepare(
- "SELECT fields FROM {$wpdb->prefix}wpforms_entries WHERE entry_id = %d",
- $entry_id,
- )
- );
-
- $entry_fields = json_decode($entry_fields, true);
-
- foreach ( $entry_fields as $field_id => $field ) {
- if ( !isset( $field['type'] ) || $field['type'] !== self::UPLOAD_FIELD_TYPE ) {
- continue;
- }
-
- // If uploads were saved to the media library
- if ( isset( $field['attachment_id'] ) && !empty($field['attachment_id']) ) {
- continue;
- }
-
- $url = isset($field['value']) ? $field['value'] : false;
-
- if ( empty($url) ) {
- continue;
- }
-
- $name = str_replace( trailingslashit( ud_get_stateless_media()->get_gs_host() ), '', $url);
-
- do_action('sm:sync::deleteFile', $name);
- }
-
- } catch (\Throwable $e) {
- error_log( $e->getMessage() );
- }
- }
-
- /**
- * Delete files from GCS when emptying entries trash.
- */
- public function before_empty_trash($entry_ids) {
- foreach ( $entry_ids as $id ) {
- $this->pre_delete_entries($id);
- }
- }
-
- /**
- * Filter files created by WPForms for sync.
- *
- * @param array $file_list
- * @return array
- */
- public function sync_non_media_files($file_list) {
- if ( !method_exists('\wpCloud\StatelessMedia\Utility', 'get_files') ) {
- Helper::log('WP-Stateless version too old, please update.');
-
- return $file_list;
- }
-
- $dir = apply_filters('wp_stateless_addon_sync_files_path', '', self::STORAGE_PATH);
-
- if (is_dir($dir)) {
- // Getting all the files from dir recursively.
- $files = Utility::get_files($dir);
-
- // validating and adding to the $files array.
- foreach ($files as $file) {
- if (!file_exists($file)) {
- continue;
- }
-
- // filter temporary logs
- if (strpos($file, self::TMP_PATH) !== false) {
- continue;
- }
-
- $file = self::STORAGE_PATH . str_replace( $dir, '', wp_normalize_path($file) );
- $file = trim($file, '/');
-
- if ( !in_array($file, $file_list) ) {
- $file_list[] = $file;
- }
- }
- }
-
- return $file_list;
- }
-
- /**
- * Delete files from GCS when file deleted from entry.
- */
- public function pre_delete_entry_fields($row_id, $primary_key) {
- // other cases are handled by other hooks
- if ( $primary_key !== 'id' ) {
- return;
- }
-
- global $wpdb;
-
- try {
- // WPForms uses direct database access and ignores caching, we should too
- // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
- $value = $wpdb->get_var(
- $wpdb->prepare(
- "SELECT value FROM {$wpdb->prefix}wpforms_entry_fields WHERE id = %d",
- $row_id,
- )
- );
-
- // Not a file or not on GCS
- if ( strpos( $value, ud_get_stateless_media()->get_gs_host() ) === false ) {
- return;
- }
-
- // Not a WPForms file or Media Library file
- if ( $this->storage_position($value) === false ) {
- return;
- }
-
- $name = str_replace( trailingslashit( ud_get_stateless_media()->get_gs_host() ), '', $value);
-
- do_action('sm:sync::deleteFile', $name);
- } catch (\Throwable $e) {
- error_log( $e->getMessage() );
- }
- }
-
- /**
- * Show message in Admin Panel when Modern upload style is used during using Stateless mode
- */
- public function show_message() {
- if ( !ud_get_stateless_media()->is_mode('stateless') ) {
- return;
- }
-
- $message_option = get_option(self::MESSAGE_KEY, []);
-
- if ( empty($message_option) ) {
- return;
- }
-
- $form_names = array_filter( array_values($message_option) );
-
- if ( empty($form_names) ) {
- return;
- }
-
- $form_names = implode(', ', $form_names);
- $form_names = '' . $form_names . '';
-
- $message = __('The File Upload field with a Modern style is not compatible with Stateless mode. Change the WPForms field style to Classic or use another WP-Stateless mode with the Modern field style. Affected Form: %s', ud_get_stateless_media()->domain);
- $message = sprintf($message, $form_names);
-
- ud_get_stateless_media()->errors->add([
- 'title' => __('WP-Stateless: Problem Detected With WPForms', ud_get_stateless_media()->domain),
- 'message' => $message,
- 'key' => self::MESSAGE_KEY,
- ], 'warning');
- }
-
- /**
- * When saving form - show warning for the Modern upload style during using Stateless mode
- */
- public function builder_save_form($form_id, $form_data) {
- $fields = is_array($form_data) && isset( $form_data['fields'] ) ? $form_data['fields'] : [];
- $message_option = get_option(self::MESSAGE_KEY, []);
- $found = false;
-
- foreach ( $fields as $field ) {
- if ( !isset( $field['type'] ) || $field['type'] !== self::UPLOAD_FIELD_TYPE ) {
- continue;
- }
-
- if ( isset( $field['style'] ) && $field['style'] == 'modern' ) {
- $found = true;
- break;
- }
- }
-
- if ( $found ) {
- $title = isset( $form_data['settings']['form_title'] )
- ? $form_data['settings']['form_title']
- : sprintf( __('Form %d', ud_get_stateless_media()->domain), $form_id);
-
- $message_option[$form_id] = $title;
-
- delete_option(self::DISMISSED_MESSAGE_KEY);
- } else {
- unset($message_option[$form_id]);
- }
-
- if ( empty($message_option) ) {
- delete_option(self::MESSAGE_KEY);
- } else {
- update_option(self::MESSAGE_KEY, $message_option);
- }
- }
- }
- }
-}
diff --git a/lib/classes/status/class-info-stateless.php b/lib/classes/status/class-info-stateless.php
index 1be68e715..bb4f3ac0e 100644
--- a/lib/classes/status/class-info-stateless.php
+++ b/lib/classes/status/class-info-stateless.php
@@ -306,6 +306,18 @@ public function get_settings_values($values) {
'label' => __('Dynamic Image Support', ud_get_stateless_media()->domain),
'value' => $sm['dynamic_image_support'],
],
+ 'use_api_siteurl' => [
+ 'label' => __('Use Site URL for REST API Requests', ud_get_stateless_media()->domain),
+ 'value' => $sm['use_api_siteurl'],
+ ],
+ 'api_status' => [
+ 'label' => __('REST API Status', ud_get_stateless_media()->domain),
+ 'value' => '%api_status%',
+ ],
+ 'ajax_status' => [
+ 'label' => __('AJAX Status', ud_get_stateless_media()->domain),
+ 'value' => '%ajax_status%',
+ ],
'use_postmeta' => [
'label' => __('Use Post Meta', ud_get_stateless_media()->domain),
'value' => $sm['use_postmeta'],
diff --git a/lib/classes/status/class-info.php b/lib/classes/status/class-info.php
index 0a43f4dfc..e3f74f7ec 100644
--- a/lib/classes/status/class-info.php
+++ b/lib/classes/status/class-info.php
@@ -21,6 +21,8 @@ protected function __construct() {
}
private function _init_hooks() {
+ add_action('wp_ajax_stateless_check_ajax', [$this, 'check_ajax']);
+
add_action('wp_stateless_status_tab_content', [$this, 'tab_content'], 10);
add_filter('wp_stateless_status_tab_visible', array($this, 'status_tab_visible'), 10, 1);
@@ -35,6 +37,22 @@ private function _init_hooks() {
add_filter('wp_stateless_status_info_values_wordpress', [$this, 'get_wordpress_plugins'], 40);
}
+ /**
+ * Check AJAX requests are working
+ */
+ public function check_ajax() {
+ if ( !check_ajax_referer('stateless_check_ajax') ) {
+ wp_send_json_error([
+ 'status' => 'Error',
+ 'message' => __('Invalid nonce', ud_get_stateless_media()->domain),
+ ]);
+ }
+
+ wp_send_json_success([
+ 'status' => 'Ok',
+ ]);
+ }
+
/**
* Get boolean value (Yes/No)
*
@@ -167,6 +185,14 @@ public function get_php_modules($values = []) {
*/
public function get_wordpress_network_values($values = []) {
$rows = [
+ 'home_url' => [
+ 'label' => __('Home URL', ud_get_stateless_media()->domain),
+ 'value' => get_bloginfo( 'url' ),
+ ],
+ 'site_url' => [
+ 'label' => __('Site URL', ud_get_stateless_media()->domain),
+ 'value' => get_bloginfo( 'wpurl' ),
+ ],
'version' => [
'label' => __('Version', ud_get_stateless_media()->domain),
'value' => get_bloginfo('version'),
diff --git a/readme.md b/readme.md
index 4091094f1..bf52108a9 100644
--- a/readme.md
+++ b/readme.md
@@ -37,9 +37,13 @@ New to Google Cloud? Google is offering you a [$300 credit](https://console.clou
* [Elementor Website Builder Addon](https://wordpress.org/plugins/wp-stateless-elementor-website-builder-addon/)
* [Gravity Forms Addon](https://wordpress.org/plugins/wp-stateless-gravity-forms-addon/)
* [Gravity Forms Signature Addon](https://wordpress.org/plugins/wp-stateless-gravity-forms-signature-addon/)
+* [WPForms Addon](https://wordpress.org/plugins/wp-stateless-wpforms-addon/)
* [WooCommerce Addon](https://wordpress.org/plugins/wp-stateless-woocommerce-addon/)
+* [Easy Digital Downloads Addon](https://wordpress.org/plugins/wp-stateless-easy-digital-downloads-addon/)
+* [LiteSpeed Cache Addon](https://wordpress.org/plugins/wp-stateless-litespeed-cache-addon/)
* [Divi Theme Addon](https://wordpress.org/plugins/wp-stateless-divi-theme-addon/)
* [SiteOrigin CSS Addon](https://wordpress.org/plugins/wp-stateless-siteorigin-css-addon/)
+* [SiteOrigin Widgets Bundle Addon](https://wordpress.org/plugins/wp-stateless-siteorigin-widgets-bundle-addon/)
* [BuddyBoss Platform Addon](https://wordpress.org/plugins/wp-stateless-buddyboss-platform-addon/)
### Support, Feedback, & Contribute
diff --git a/readme.txt b/readme.txt
index 0570a2e85..9d2e86e1b 100644
--- a/readme.txt
+++ b/readme.txt
@@ -6,7 +6,7 @@ License: GPLv2 or later
Requires PHP: 8.0
Requires at least: 5.0
Tested up to: 6.6.2
-Stable tag: 4.1.1
+Stable tag: 4.1.2
Upload and serve your WordPress media files from Google Cloud Storage.
@@ -47,9 +47,13 @@ New to Google Cloud? Google is offering you a [$300 credit](https://console.clou
* [Elementor Website Builder Addon](https://wordpress.org/plugins/wp-stateless-elementor-website-builder-addon/)
* [Gravity Forms Addon](https://wordpress.org/plugins/wp-stateless-gravity-forms-addon/)
* [Gravity Forms Signature Addon](https://wordpress.org/plugins/wp-stateless-gravity-forms-signature-addon/)
+* [WPForms Addon](https://wordpress.org/plugins/wp-stateless-wpforms-addon/)
* [WooCommerce Addon](https://wordpress.org/plugins/wp-stateless-woocommerce-addon/)
+* [Easy Digital Downloads Addon](https://wordpress.org/plugins/wp-stateless-easy-digital-downloads-addon/)
+* [LiteSpeed Cache Addon](https://wordpress.org/plugins/wp-stateless-litespeed-cache-addon/)
* [Divi Theme Addon](https://wordpress.org/plugins/wp-stateless-divi-theme-addon/)
* [SiteOrigin CSS Addon](https://wordpress.org/plugins/wp-stateless-siteorigin-css-addon/)
+* [SiteOrigin Widgets Bundle Addon](https://wordpress.org/plugins/wp-stateless-siteorigin-widgets-bundle-addon/)
* [BuddyBoss Platform Addon](https://wordpress.org/plugins/wp-stateless-buddyboss-platform-addon/)
= Support, Feedback, & Contribute =
@@ -129,6 +133,15 @@ Before upgrading to WP-Stateless 3.2.0, please, make sure you use PHP 7.2 or abo
Before upgrading to WP-Stateless 3.0, please, make sure you tested it on your development environment.
== Changelog ==
+= 4.1.2 =
+* ENHANCEMENT - added `REST API Endpoint` setting, which useful when WordPress dashboard and frontend website utilize different domain names.
+* ENHANCEMENT - extended `Status Info` with the information to help diagnose REST API or AJAX issues.
+* COMPATIBILITY - SiteOrigin Widgets Bundle Compatibility replaced with [WP-Stateless - SiteOrigin Widgets Bundle Addon](https://wordpress.org/plugins/wp-stateless-siteorigin-widgets-bundle-addon/).
+* COMPATIBILITY - WPForms Compatibility replaced with [WP-Stateless - WPForms Addon](https://wordpress.org/plugins/wp-stateless-wpforms-addon/).
+* COMPATIBILITY - Easy Digital Downloads Compatibility replaced with [WP-Stateless - Easy Digital Downloads Addon](* COMPATIBILITY - Easy Digital Downloads Compatibility replaced with [WP-Stateless - Easy Digital Downloads Addon](https://wordpress.org/plugins/wp-stateless-easy-digital-downloads-addon/).
+* COMPATIBILITY - LiteSpeed Cache Compatibility replaced with [WP-Stateless - LiteSpeed Cache Addon](https://wordpress.org/plugins/wp-stateless-litespeed-cache-addon/).
+* FIX: remove PHP warning on `Status` settings tab.
+
= 4.1.1 =
* FIX - cache issues during Data Optimization.
diff --git a/static/data/addons.php b/static/data/addons.php
index 59d1b7e00..b901e60a3 100644
--- a/static/data/addons.php
+++ b/static/data/addons.php
@@ -97,4 +97,44 @@
'hubspot_id' => '151480507684',
],
+ 'siteorigin-widgets-bundle' => [
+ 'title' => 'SiteOrigin Widgets Bundle',
+ 'plugin_files' => ['so-widgets-bundle/so-widgets-bundle.php'],
+ 'addon_file' => 'wp-stateless-siteorigin-widgets-bundle-addon/wp-stateless-siteorigin-widgets-bundle-addon.php',
+ 'icon' => 'https://ps.w.org/so-widgets-bundle/assets/icon.svg',
+ 'repo' => 'udx/wp-stateless-siteorigin-widgets-bundle-addon',
+ 'wp' => 'https://wordpress.org/plugins/wp-stateless-siteorigin-widgets-bundle-addon/',
+ 'hubspot_id' => '151480507657',
+ ],
+
+ 'wpforms' => [
+ 'title' => 'WPForms',
+ 'plugin_files' => ['wpforms-lite/wpforms.php', 'wpforms/wpforms.php'],
+ 'addon_file' => 'wp-stateless-wpforms-addon/wp-stateless-wpforms-addon.php',
+ 'icon' => 'https://ps.w.org/wpforms-lite/assets/icon.svg',
+ 'repo' => 'udx/wp-stateless-wpforms-addon',
+ 'wp' => 'https://wordpress.org/plugins/wp-stateless-wpforms-addon/',
+ 'hubspot_id' => '151481399840',
+ ],
+
+ 'edd' => [
+ 'title' => 'Easy Digital Downloads',
+ 'plugin_files' => ['easy-digital-downloads/easy-digital-downloads.php'],
+ 'addon_file' => 'wp-stateless-easy-digital-downloads-addon/wp-stateless-easy-digital-downloads-addon.php',
+ 'icon' => 'https://ps.w.org/easy-digital-downloads/assets/icon.svg',
+ 'repo' => 'udx/wp-stateless-easy-digital-downloads-addon',
+ 'wp' => 'https://wordpress.org/plugins/wp-stateless-easy-digital-downloads-addon/',
+ 'hubspot_id' => '151481399833',
+ ],
+
+ 'lite-speed-cache' => [
+ 'title' => 'LiteSpeed Cache',
+ 'plugin_files' => ['litespeed-cache/litespeed-cache.php'],
+ 'addon_file' => 'wp-stateless-litespeed-cache-addon/wp-stateless-litespeed-cache-addon.php',
+ 'icon' => 'https://ps.w.org/litespeed-cache/assets/icon-128x128.png',
+ 'repo' => 'udx/wp-stateless-litespeed-cache-addon',
+ 'wp' => 'https://wordpress.org/plugins/wp-stateless-litespeed-cache-addon/',
+ 'hubspot_id' => '151480507763',
+ ],
+
];
diff --git a/static/scripts/wp-stateless-batch.js b/static/scripts/wp-stateless-batch.js
index 651b30ec6..125f00fd9 100644
--- a/static/scripts/wp-stateless-batch.js
+++ b/static/scripts/wp-stateless-batch.js
@@ -1,6 +1,6 @@
wpStatelessBatch = {
token: window.wp_stateless_batch.REST_API_TOKEN,
- apiRoot: window.wpApiSettings.root + 'wp-stateless/v1/batch/',
+ apiRoot: window.wp_stateless_batch.api_root + 'batch/',
interval: null,
startPolling: function () {
diff --git a/static/scripts/wp-stateless-settings.js b/static/scripts/wp-stateless-settings.js
index 887ae2a7a..6981405a7 100644
--- a/static/scripts/wp-stateless-settings.js
+++ b/static/scripts/wp-stateless-settings.js
@@ -55,6 +55,7 @@ jQuery(document).ready(function ($) {
}
})
+ // Copy Status Info to clipboard
var clipboard = new ClipboardJS('.stateless-info-heading .copy-button')
clipboard.on('success', function(e) {
@@ -64,4 +65,39 @@ jQuery(document).ready(function ($) {
$('.stateless-info-copy-success').fadeOut(500);
}, 5000);
})
+
+ // Check if API and AJAX is available
+ function setServiceStatus(id, status) {
+ var data = $('.stateless-info-heading .button.copy-button').attr('data-clipboard-text');
+ $('.stateless-info-heading .button.copy-button').attr( 'data-clipboard-text', data.replace('%' + id + '%', status));
+
+ $(`#stateless-info-block-stateless .${id} .value`).text(status);
+ }
+
+ $.ajax({
+ method: 'GET',
+ url: window.wp_stateless_configs.api_root + 'status',
+ })
+ .then(function() {
+ setServiceStatus( 'api_status', window.wp_stateless_configs.text_ok );
+ })
+ .fail(function() {
+ setServiceStatus( 'api_status', window.wp_stateless_configs.text_fail );
+ })
+
+ $.ajax({
+ method: 'POST',
+ url: window.wp_stateless_configs.ajaxurl,
+ data: {
+ action: 'stateless_check_ajax',
+ _ajax_nonce: window.wp_stateless_configs.stateless_check_ajax_nonce,
+ }
+ })
+ .then(function() {
+ setServiceStatus( 'ajax_status', window.wp_stateless_configs.text_ok );
+ })
+ .fail(function() {
+ setServiceStatus( 'ajax_status', window.wp_stateless_configs.text_fail );
+ })
+
})
diff --git a/static/scripts/wp-stateless.js b/static/scripts/wp-stateless.js
index a2a02b4f7..5bcd1926d 100644
--- a/static/scripts/wp-stateless.js
+++ b/static/scripts/wp-stateless.js
@@ -398,8 +398,8 @@ wpStatelessProcessingApp = {
canRun: true,
processes: [],
token: window.wp_stateless_configs.REST_API_TOKEN,
- apiRoot: window.wpApiSettings.root + 'wp-stateless/v1/sync/',
-
+ apiRoot: window.wp_stateless_configs.api_root + 'sync/',
+
blockUI: function () {
this.canRun = false
diff --git a/static/views/settings-sections/general.php b/static/views/settings-sections/general.php
index 1282d4597..aad4a9861 100644
--- a/static/views/settings-sections/general.php
+++ b/static/views/settings-sections/general.php
@@ -100,6 +100,25 @@
+
domain); ?>
+
+
+
+
+
+
+
+
+ WP_HOME endpoint for REST API requests. If you encounter problems with synchronization or data optimization functions, try using the WP_SITEURL option instead. This is useful if your WordPress dashboard and frontend website utilize different domain names, such as with a headless CMS configuration.', ud_get_stateless_media()->domain); ?>
+