From 003d1a314be7d7c4b0397b4ca9825b8f69626144 Mon Sep 17 00:00:00 2001 From: Sybre Waaijer Date: Wed, 17 Jul 2024 13:12:33 +0200 Subject: [PATCH] Enforce selective autoloading with WP 6.6 options API. --- autodescription.php | 6 ++--- bootstrap/plugin-activation.php | 4 +-- bootstrap/upgrade.php | 29 +++++++++++----------- inc/classes/data/admin/plugin.class.php | 2 +- inc/classes/data/filter/sanitize.class.php | 3 ++- inc/classes/data/plugin.class.php | 6 ++--- inc/classes/data/plugin/setup.class.php | 2 +- inc/classes/internal/deprecated.class.php | 5 ++-- inc/classes/meta/robots/args.class.php | 2 +- inc/classes/meta/robots/front.class.php | 2 +- readme.txt | 1 + 11 files changed, 33 insertions(+), 29 deletions(-) diff --git a/autodescription.php b/autodescription.php index e69e37f0..ed87b513 100644 --- a/autodescription.php +++ b/autodescription.php @@ -3,7 +3,7 @@ * Plugin Name: The SEO Framework * Plugin URI: https://theseoframework.com/ * Description: An automated, advanced, accessible, unbranded and extremely fast SEO solution for your WordPress website. - * Version: 5.0.7-dev-12 + * Version: 5.0.7-dev-13 * Author: The SEO Framework Team * Author URI: https://theseoframework.com/ * License: GPLv3 @@ -132,8 +132,8 @@ // define( 'THE_SEO_FRAMEWORK_DEBUG', true ); // delete_option( 'the_seo_framework_upgraded_db_version' ); // ( $_GET['reset_tsf_upgrade'] ?? 0 ) and delete_option( 'the_seo_framework_upgraded_db_version' ) and delete_option( 'the_seo_framework_initial_db_version' ); -// ( $_GET['downgrade_tsf'] ?? 0 ) and update_option( 'the_seo_framework_upgraded_db_version', (string) (int) $_GET['downgrade_tsf'] ); -// ( $_GET['downgrade_tsf_initial'] ?? 0 ) and update_option( 'the_seo_framework_initial_db_version', (string) (int) $_GET['downgrade_tsf_initial'] ); +// ( $_GET['downgrade_tsf'] ?? 0 ) and update_option( 'the_seo_framework_upgraded_db_version', (string) (int) $_GET['downgrade_tsf'], true ); +// ( $_GET['downgrade_tsf_initial'] ?? 0 ) and update_option( 'the_seo_framework_initial_db_version', (string) (int) $_GET['downgrade_tsf_initial'], false ); // ( $_GET['tsf_headless'] ?? 0 ) and define( 'THE_SEO_FRAMEWORK_HEADLESS', $_GET['tsf_headless'] === 'true' ?: $_GET['tsf_headless'] ); // add_action( 'admin_footer', function () { print( '' ); } ); // } diff --git a/bootstrap/plugin-activation.php b/bootstrap/plugin-activation.php index c215af42..829d3a99 100644 --- a/bootstrap/plugin-activation.php +++ b/bootstrap/plugin-activation.php @@ -56,8 +56,8 @@ if ( \is_array( $temp_options ) ) $temp_options['update_buster'] = time(); - $_success = \update_option( $setting, $temp_options, 'yes' ); + $_success = \update_option( $setting, $temp_options, true ); if ( $_success ) - \update_option( $setting, $options, 'yes' ); + \update_option( $setting, $options, true ); } } diff --git a/bootstrap/upgrade.php b/bootstrap/upgrade.php index 393063db..5f6ef00e 100644 --- a/bootstrap/upgrade.php +++ b/bootstrap/upgrade.php @@ -139,7 +139,7 @@ function _do_upgrade() { if ( ! \get_option( 'the_seo_framework_initial_db_version' ) ) { // Sets to previous if previous is known. This is a late addition. New sites default to \THE_SEO_FRAMEWORK_DB_VERSION. - \update_option( 'the_seo_framework_initial_db_version', $previous_version ?: \THE_SEO_FRAMEWORK_DB_VERSION, 'no' ); + \update_option( 'the_seo_framework_initial_db_version', $previous_version ?: \THE_SEO_FRAMEWORK_DB_VERSION, false ); } // Don't run the upgrade cycle if the user downgraded. Downgrade, instead. @@ -247,23 +247,24 @@ function _set_upgrade_lock( $release_timeout ) { $lock_option = _get_lock_option(); - $lock_result = $wpdb->query( + // TODO WP 6.6+ change 'no' to 'off'. + $lock = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_option, - time() - ) + time(), + ), ); - if ( ! $lock_result ) { - $lock_result = \get_option( $lock_option ); + if ( ! $lock ) { + $lock = \get_option( $lock_option ); // If a lock couldn't be created, and there isn't a lock, bail. - if ( ! $lock_result ) + if ( ! $lock ) return false; // Check to see if the lock is still valid. If it is, bail. - if ( $lock_result > ( time() - $release_timeout ) ) + if ( $lock > ( time() - $release_timeout ) ) return false; // There must exist an expired lock, clear it... @@ -274,7 +275,7 @@ function _set_upgrade_lock( $release_timeout ) { } // Update the lock, as by this point we've definitely got a lock, just need to fire the actions. - \update_option( $lock_option, time() ); + \update_option( $lock_option, time(), true ); return true; } @@ -301,7 +302,7 @@ function _release_upgrade_lock() { */ function _set_version( $version = \THE_SEO_FRAMEWORK_DB_VERSION ) { - \update_option( 'the_seo_framework_upgraded_db_version', (string) $version ); + \update_option( 'the_seo_framework_upgraded_db_version', (string) $version, true ); return (string) $version; } @@ -598,7 +599,7 @@ function _add_upgrade_notice( $notice = '' ) { */ function _do_upgrade_1() { // Here, `Plugin\Setup::get_default_options()` will get called 3 times in a row. Alas. - \add_option( \THE_SEO_FRAMEWORK_SITE_OPTIONS, Data\Plugin\Setup::get_default_options() ); + \add_option( \THE_SEO_FRAMEWORK_SITE_OPTIONS, Data\Plugin\Setup::get_default_options(), '', true ); } /** @@ -618,7 +619,7 @@ function _do_upgrade_2701() { \add_term_meta( $term_id, \THE_SEO_FRAMEWORK_TERM_OPTIONS, $meta, true ); // Rudimentary test for remaining ~300 users of earlier versions passed, set initial version to 2600. - \update_option( 'the_seo_framework_initial_db_version', '2600', 'no' ); + \update_option( 'the_seo_framework_initial_db_version', '2600', false ); } } @@ -873,7 +874,7 @@ function _do_upgrade_4270() { function _do_upgrade_5001() { // Not a public "setting" -- only add the option to prevent additional db-queries when it's yet to be populated. - \add_option( \THE_SEO_FRAMEWORK_SITE_CACHE, Data\Plugin\Setup::get_default_site_caches() ); + \add_option( \THE_SEO_FRAMEWORK_SITE_CACHE, Data\Plugin\Setup::get_default_site_caches(), '', true ); if ( \get_option( 'the_seo_framework_initial_db_version' ) < '5001' ) { Data\Plugin::update_option( @@ -884,7 +885,7 @@ function _do_upgrade_5001() { $site_cache = \get_option( 'autodescription-updates-cache' ) ?: []; if ( $site_cache ) { // Try to use the options API as much as possible, instead of using $wpdb->update(). - \update_option( \THE_SEO_FRAMEWORK_SITE_CACHE, $site_cache ); + \update_option( \THE_SEO_FRAMEWORK_SITE_CACHE, $site_cache, true ); // The option holds only generated data that can be regenerated easily. // On downgrade, this will be repopulated. \delete_option( 'autodescription-updates-cache' ); diff --git a/inc/classes/data/admin/plugin.class.php b/inc/classes/data/admin/plugin.class.php index e8d4546f..c7a97c9c 100644 --- a/inc/classes/data/admin/plugin.class.php +++ b/inc/classes/data/admin/plugin.class.php @@ -193,7 +193,7 @@ public static function set_option_updated_notice() { * @since 5.0.0 Moved from `\The_SEO_Framework\Load`. */ public static function update_db_version() { - \update_option( 'the_seo_framework_upgraded_db_version', \THE_SEO_FRAMEWORK_DB_VERSION ); + \update_option( 'the_seo_framework_upgraded_db_version', \THE_SEO_FRAMEWORK_DB_VERSION, true ); } /** diff --git a/inc/classes/data/filter/sanitize.class.php b/inc/classes/data/filter/sanitize.class.php index 6aca6c91..c4710990 100644 --- a/inc/classes/data/filter/sanitize.class.php +++ b/inc/classes/data/filter/sanitize.class.php @@ -314,12 +314,13 @@ public static function tab_to_space( $text ) { * @since 5.0.0 1. Moved from `\The_SEO_Framework\Load`. * 2. Renamed from `s_qubit`. * 3. Now considers .3334 the turnover point, instead of 0.33000...0001. + * @since 5.0.7 Now considers .3333 the turnover point for the negative side, instead of -0.3333999...999. * * @param float|int $value The qubit to test; ideally be -1, 0, or 1. * @return int -1, 0, or 1. */ public static function qubit( $value ) { - return $value >= .3334 <=> -.3334 >= $value; + return $value >= .3334 <=> -.3333 >= $value; } /** diff --git a/inc/classes/data/plugin.class.php b/inc/classes/data/plugin.class.php index e29fa545..a5310c55 100644 --- a/inc/classes/data/plugin.class.php +++ b/inc/classes/data/plugin.class.php @@ -156,7 +156,7 @@ public static function update_option( $option, $value = '' ) { Plugin\PTA::flush_cache(); - return \update_option( \THE_SEO_FRAMEWORK_SITE_OPTIONS, $options ); + return \update_option( \THE_SEO_FRAMEWORK_SITE_OPTIONS, $options, true ); } /** @@ -213,7 +213,7 @@ public static function update_site_cache( $cache, $value = '' ) { static::$site_cache_memo = $site_cache; - return \update_option( \THE_SEO_FRAMEWORK_SITE_CACHE, $site_cache ); + return \update_option( \THE_SEO_FRAMEWORK_SITE_CACHE, $site_cache, true ); } /** @@ -234,6 +234,6 @@ public static function delete_site_cache( $cache ) { static::$site_cache_memo = $site_cache; - return \update_option( \THE_SEO_FRAMEWORK_SITE_CACHE, $site_cache ); + return \update_option( \THE_SEO_FRAMEWORK_SITE_CACHE, $site_cache, true ); } } diff --git a/inc/classes/data/plugin/setup.class.php b/inc/classes/data/plugin/setup.class.php index b66a614c..0c0a767d 100644 --- a/inc/classes/data/plugin/setup.class.php +++ b/inc/classes/data/plugin/setup.class.php @@ -61,7 +61,7 @@ class Setup { */ public static function reset_options() { - $success = \update_option( \THE_SEO_FRAMEWORK_SITE_OPTIONS, static::get_default_options() ); + $success = \update_option( \THE_SEO_FRAMEWORK_SITE_OPTIONS, static::get_default_options(), true ); if ( $success ) Data\Plugin::refresh_static_properties(); diff --git a/inc/classes/internal/deprecated.class.php b/inc/classes/internal/deprecated.class.php index f50c16db..4caea856 100644 --- a/inc/classes/internal/deprecated.class.php +++ b/inc/classes/internal/deprecated.class.php @@ -5058,7 +5058,8 @@ public function update_settings( $new_option = '', $settings_field = '' ) { return \update_option( $settings_field, - \wp_parse_args( $new_option, \get_option( $settings_field ) ) + \wp_parse_args( $new_option, \get_option( $settings_field ) ), + true, ); } @@ -6648,7 +6649,7 @@ public function register_settings() { */ public function update_db_version() { \tsf()->_deprecated_function( 'tsf()->update_db_version()', '5.0.0' ); - \update_option( 'the_seo_framework_upgraded_db_version', THE_SEO_FRAMEWORK_DB_VERSION ); + \update_option( 'the_seo_framework_upgraded_db_version', THE_SEO_FRAMEWORK_DB_VERSION, true ); } /** diff --git a/inc/classes/meta/robots/args.class.php b/inc/classes/meta/robots/args.class.php index 40dfc86d..d93a7754 100644 --- a/inc/classes/meta/robots/args.class.php +++ b/inc/classes/meta/robots/args.class.php @@ -89,7 +89,7 @@ protected static function assert_no( $type ) { case false: // Page doesn't support metadata. break; - case $qubit < -.3334: + case $qubit < -.3333: // 'Force' index. yield 'meta_qubit_force' => false; // Override with index protection. diff --git a/inc/classes/meta/robots/front.class.php b/inc/classes/meta/robots/front.class.php index 30c28ee9..62072382 100644 --- a/inc/classes/meta/robots/front.class.php +++ b/inc/classes/meta/robots/front.class.php @@ -82,7 +82,7 @@ protected static function assert_no( $type ) { case false: // Page doesn't support metadata. break; - case $qubit < -.3334: + case $qubit < -.3333: // 'Force' index. yield 'meta_qubit_force' => false; // Override with index protection. diff --git a/readme.txt b/readme.txt index 85290fbd..dd55a280 100644 --- a/readme.txt +++ b/readme.txt @@ -344,6 +344,7 @@ TODO test image type support and warn users about Facebook not supporting webp ( * Improved the Markdown parser's performance by using fewer memory operations. * **Other:** * Removed support for `-ms-clear` and `-ms-input-placeholder` vendor-specific CSS pseudo-selectors. + * We're now stipulant about the autoloading status of every option. This is because WordPress 6.6 makes up its own mind on the autoloading state based on arbitrary and untested values. Although that shouldn't affect TSF's options directly, one could filter it so it could become our problem. The distinct annotation of always autoloading (and toggling that when the plugin (de)activates) will ensure TSF always performs as intended. * **Fixed:** * Resolved an issue where the deprecated method `tsf()->og_locale()` didn't return the meta tag and gave a warning instead. * `tsf()->fetch_locale()` is now properly deprecated and returns its original value.