Skip to content

Commit

Permalink
Enforce selective autoloading with WP 6.6 options API.
Browse files Browse the repository at this point in the history
  • Loading branch information
sybrew committed Jul 17, 2024
1 parent 5bf612f commit 003d1a3
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 29 deletions.
6 changes: 3 additions & 3 deletions autodescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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( '<script>jQuery.migrateMute=true;</script>' ); } );
// }
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/plugin-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
29 changes: 15 additions & 14 deletions bootstrap/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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...
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 );
}

/**
Expand All @@ -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 );
}
}

Expand Down Expand Up @@ -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(
Expand All @@ -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' );
Expand Down
2 changes: 1 addition & 1 deletion inc/classes/data/admin/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
3 changes: 2 additions & 1 deletion inc/classes/data/filter/sanitize.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions inc/classes/data/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down Expand Up @@ -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 );
}

/**
Expand All @@ -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 );
}
}
2 changes: 1 addition & 1 deletion inc/classes/data/plugin/setup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions inc/classes/internal/deprecated.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down Expand Up @@ -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 );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/classes/meta/robots/args.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion inc/classes/meta/robots/front.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 003d1a3

Please sign in to comment.