Skip to content

Commit

Permalink
Merge pull request #733 from udx/latest
Browse files Browse the repository at this point in the history
Latest => 4.0
  • Loading branch information
balexey88 authored Apr 3, 2024
2 parents c69f356 + 8bd3611 commit 7137bf8
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 14 deletions.
4 changes: 3 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* NEW - added filter `wp_stateless_get_file_sizes`, retrieves the GCS file data for image sizes, should be used instead of getting `sm_cloud` postmeta directly.
* NEW - added filter `wp_stateless_get_file_meta`, retrieves all GCS file meta data, should be used instead of getting `sm_cloud` postmeta directly.
* NEW - added filter `wp_stateless_get_file_meta_value`, retrieves the GCS file meta data by meta_key, should be used instead of getting `sm_cloud` postmeta directly.
* NEW - added setting allowing to change email for WP-Stateless notifications.
* NEW - added filter `wp_stateless_get_setting_...` which allows to override any WP-Stateless setting.
* NEW - added setting "Send Status Emails" allowing to change email for WP-Stateless notifications.
* NEW - added setting "Use Post Meta" allowing to switch back to using `postmeta` instead of custom DB tables. Can be used in case of issues after upgrading to 4.0.0.
* NEW - added new Settings tab `Addons`, which contains the list of WP-Stateless Addons, which replace Compatibilities.
* NEW - added new Settings tab `Status`, which contains status and health information related to Google Cloud Storage and WP-Stateless.
* NEW - CLI command `wp stateless migrate` to list and operate data optimizations.
Expand Down
4 changes: 3 additions & 1 deletion changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* NEW - added filter `wp_stateless_get_file_sizes`, retrieves the GCS file data for image sizes, should be used instead of getting `sm_cloud` postmeta directly.
* NEW - added filter `wp_stateless_get_file_meta`, retrieves all GCS file meta data, should be used instead of getting `sm_cloud` postmeta directly.
* NEW - added filter `wp_stateless_get_file_meta_value`, retrieves the GCS file meta data by meta_key, should be used instead of getting `sm_cloud` postmeta directly.
* NEW - added setting allowing to change email for WP-Stateless notifications.
* NEW - added filter `wp_stateless_get_setting_...` which allows to override any WP-Stateless setting.
* NEW - added setting "Send Status Emails" allowing to change email for WP-Stateless notifications.
* NEW - added setting "Use Post Meta" allowing to switch back to using `postmeta` instead of custom DB tables. Can be used in case of issues after upgrading to 4.0.0.
* NEW - added new Settings tab `Addons`, which contains the list of WP-Stateless Addons, which replace Compatibilities.
* NEW - added new Settings tab `Status`, which contains status and health information related to Google Cloud Storage and WP-Stateless.
* NEW - CLI command `wp stateless migrate` to list and operate data optimizations.
Expand Down
4 changes: 3 additions & 1 deletion lib/classes/class-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ protected function __construct($args) {

parent::__construct($args);

self::$version = $args['version'] ?? self::$version;

/**
* Add custom args to api ping request
*/
Expand Down Expand Up @@ -1874,7 +1876,7 @@ public function attachment_url_to_postid($post_id, $url) {
// User can use this constant if they change the Bucket Folder (root_dir) after uploading image.
// This can be little slow at first run.
if (empty($post_id)) {
if ( !defined('WP_STATELESS_POSTMETA') || !WP_STATELESS_POSTMETA ) {
if ( !$this->get('sm.use_postmeta') ) {
$query = 'SELECT post_id FROM ' . ud_stateless_db()->files . ' WHERE file_link = %s';
$post_id = $wpdb->get_var($wpdb->prepare($query, $url));
}
Expand Down
6 changes: 3 additions & 3 deletions lib/classes/class-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public function get_total_files() {
* @return array
*/
public function get_file($meta, $attachment_id, $with_sizes = false) {
if ( defined('WP_STATELESS_POSTMETA') && WP_STATELESS_POSTMETA ) {
if ( ud_get_stateless_media()->get('sm.use_postmeta') ) {
$meta = get_post_meta($attachment_id, 'sm_cloud', true);

if ( !empty($meta) ) {
Expand Down Expand Up @@ -751,7 +751,7 @@ public function get_file($meta, $attachment_id, $with_sizes = false) {
* @return array
*/
public function get_file_sizes($sizes, $attachment_id) {
if ( defined('WP_STATELESS_POSTMETA') && WP_STATELESS_POSTMETA ) {
if ( ud_get_stateless_media()->get('sm.use_postmeta') ) {
$meta = get_post_meta($attachment_id, 'sm_cloud', true);
return isset($meta['sizes']) ? $meta['sizes'] : [];
}
Expand Down Expand Up @@ -796,7 +796,7 @@ public function get_file_sizes($sizes, $attachment_id) {
* @return mixed
*/
public function get_file_meta_value($value, $post_id, $key, $default = null) {
if ( defined('WP_STATELESS_POSTMETA') && WP_STATELESS_POSTMETA ) {
if ( ud_get_stateless_media()->get('sm.use_postmeta') ) {
$meta = get_post_meta($post_id, 'sm_cloud', []);

return isset($meta[$key]) ? $meta[$key] : $default;
Expand Down
23 changes: 23 additions & 0 deletions lib/classes/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ final class Settings extends \UDX\Settings {
'dynamic_image_support' => array(['WP_STATELESS_MEDIA_ON_FLY' => 'WP_STATELESS_DYNAMIC_IMAGE_SUPPORT'], 'false'),
'status_email_type' => array('', 'true'),
'status_email_address' => array('', ''),
'use_postmeta' => array('WP_STATELESS_POSTMETA', ['false', '']),
);

private $network_only_settings = array(
Expand Down Expand Up @@ -626,6 +627,28 @@ public function processing_tab_content() {

include ud_get_stateless_media()->path('static/views/processing_interface.php', 'dir');
}

/**
* Getter for settings
*
* @param string|bool $key
* @param mixed $default
* @return mixed
*/
public function get( $key = false, $default = false ) {
$value = parent::get( $key, $default );

if ( $key === 'sm' && is_array($value) ) {
foreach ( $value as $key => $val ) {
$value[$key] = apply_filters("wp_stateless_get_setting_$key", $val, $default);
}
} else if ( is_string($key) ) {
$key = str_replace('sm.', '', $key);
$value = apply_filters("wp_stateless_get_setting_$key", $value, $default);
}

return $value;
}
}

}
Expand Down
7 changes: 5 additions & 2 deletions lib/classes/class-utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,11 @@ public static function convert_to_byte($size) {
public static function get_stateless_media_data_count() {
global $wpdb;

if ( !defined('WP_STATELESS_POSTMETA') || !WP_STATELESS_POSTMETA ) {
return ud_stateless_db()->get_total_files();
if ( !ud_get_stateless_media()->get('sm.use_postmeta') ) {
try {
return ud_stateless_db()->get_total_files();
} catch (\Throwable $th) {
}
}

$stateless_media = $wpdb->get_var($wpdb->prepare("
Expand Down
8 changes: 5 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Tags: google cloud, google cloud storage, cdn, uploads, backup
License: GPLv2 or later
Requires PHP: 8.0
Requires at least: 5.0
Tested up to: 6.4.3
Stable tag: 4.0.0-RC.1
Tested up to: 6.5.0
Stable tag: 4.0.0-RC.2

Upload and serve your WordPress media files from Google Cloud Storage.

Expand Down Expand Up @@ -127,7 +127,9 @@ Before upgrading to WP-Stateless 3.0, please, make sure you tested it on your de
* NEW - added filter `wp_stateless_get_file_sizes`, retrieves the GCS file data for image sizes, should be used instead of getting `sm_cloud` postmeta directly.
* NEW - added filter `wp_stateless_get_file_meta`, retrieves all GCS file meta data, should be used instead of getting `sm_cloud` postmeta directly.
* NEW - added filter `wp_stateless_get_file_meta_value`, retrieves the GCS file meta data by meta_key, should be used instead of getting `sm_cloud` postmeta directly.
* NEW - added setting allowing to change email for WP-Stateless notifications.
* NEW - added filter `wp_stateless_get_setting_...` which allows to override any WP-Stateless setting.
* NEW - added setting "Send Status Emails" allowing to change email for WP-Stateless notifications.
* NEW - added setting "Use Post Meta" allowing to switch back to using `postmeta` instead of custom DB tables. Can be used in case of issues after upgrading to 4.0.0.
* NEW - added new Settings tab `Addons`, which contains the list of WP-Stateless Addons, which replace Compatibilities.
* NEW - added new Settings tab `Status`, which contains status and health information related to Google Cloud Storage and WP-Stateless.
* NEW - CLI command `wp stateless migrate` to list and operate data optimizations.
Expand Down
4 changes: 2 additions & 2 deletions static/migrations/20240219175240.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ public function process_item($item) {

// Update file meta data ('fileMd5' for LiteSpeed Cache)
$key = 'fileMd5';
$md5_data = $meta[$key] ?? [];
$md5_data = $meta[$key] ?? null;

if ( !empty($meta) ) {
if ( !empty($md5_data) ) {
$data = [
'post_id' => $item,
'meta_key' => sanitize_key($key),
Expand Down
17 changes: 17 additions & 0 deletions static/views/settings-sections/file-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@

<?php _e('Upload image thumbnails generated by your theme and plugins that do not register media objects with the media library. This can lead to significant negative performance impact.', ud_get_stateless_media()->domain); ?>
</p>

<h4><?php _e('Use Post Meta', ud_get_stateless_media()->domain); ?></h4>

<p>
<select id="use_postmeta" name="sm[use_postmeta]">
<?php if (is_network_admin()) : ?>
<option value="" <?php selected( $sm->use_postmeta, '' ); ?>><?php _e('Don\'t override', ud_get_stateless_media()->domain); ?></option>
<?php endif; ?>
<option value="true" <?php selected( $sm->use_postmeta, 'true' ); ?>><?php _e('Enable', ud_get_stateless_media()->domain); ?></option>
<option value="false" <?php selected( $sm->use_postmeta, 'false' ); ?>><?php _e('Disable', ud_get_stateless_media()->domain); ?></option>
</select>
</p>

<p class="description">
<strong id="notice-use_postmeta"></strong>
<?php _e('Use post meta instead of custom WP-Stateless DB tables. Enable <strong>only</strong> if you experience technical issues after upgrading to WP-Stateless 4.0.0', ud_get_stateless_media()->domain); ?>
</p>
</fieldset>
</td>
</tr>
2 changes: 1 addition & 1 deletion wp-stateless-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://stateless.udx.io/
* Description: Upload and serve your WordPress media files from Google Cloud Storage.
* Author: UDX
* Version: 4.0.0-RC.1
* Version: 4.0.0-RC.2
* Text Domain: stateless-media
* Author URI: https://udx.io
* License: GPLv2 or later
Expand Down

0 comments on commit 7137bf8

Please sign in to comment.