[wp-trac] [WordPress Trac] #64231: Customizer fails to save when switching themes due to an orphaned setting left over from a previously active plugin

WordPress Trac noreply at wordpress.org
Tue Nov 11 13:02:17 UTC 2025


#64231: Customizer fails to save when switching themes due to an orphaned setting
left over from a previously active plugin
-----------------------------+-------------------------------------
 Reporter:  alessandrolioce  |      Owner:  (none)
     Type:  defect (bug)     |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Customize        |    Version:  6.8.3
 Severity:  normal           |   Keywords:  has-patch has-test-info
  Focuses:                   |
-----------------------------+-------------------------------------
 = Description =
 When using the Customizer and switching themes with live preview,
 WordPress fails to save due to an unrecognized setting.
 This happens when a plugin adds a custom setting to the Customizer, then
 gets deactivated before switching back to another theme.

 ⸻

 = Environment =
         •       WordPress v6.8.3
         •       Active Theme: Twenty Twenty-One (v2.6)
         •       Other used theme Twenty Twenty (v2.9)
         •       Plugin: "Adds a testing option in customizer" (used to
 register “test_orphaned_setting”)

 ⸻

 = Steps to Reproduce =
         1.      Activate the plugin that adds a testing option in the
 Customizer.
         2.      Go to Appearance > Customize.
         4.      Edit the setting under Site Identity > Test Orphaned
 Setting.
         5.      Without saving, switch to the Twenty Twenty theme using
 Live Preview, then click Activate & Publish.
         6.      Deactivate the plugin (“Adds a testing option in
 customizer”).
         7.      Go to Appearance > Customize again.
         8.      Switch the theme back to Twenty Twenty-One using Live
 Preview.
         9.      Click Activate & Publish.

 ⸻

 = Plugin that adds a testing option =

 {{{#!php
 <?php

 /**
  * Plugin Name: Adds a testing option in customizer
  */

 add_action( 'customize_register', function ( $wp_customize ) {
         $wp_customize->add_setting( 'test_orphaned_setting', array(
                 'default'    => '',
                 'type'       => 'theme_mod',
                 'capability' => 'edit_theme_options',
                 'transport'  => 'refresh',
         ) );

         $wp_customize->add_control( 'test_orphaned_setting', array(
                 'label'   => 'Test Orphaned Setting',
                 'section' => 'title_tagline',
                 'type'    => 'text',
         ) );
 } );
 }}}

 ⸻

 = Observed Behavior =
 A POST request is sent to /wp-admin/admin-ajax.php with the following
 parameters:

 {{{
 wp_customize    “on”
 customize_theme “twentytwentyone”
 nonce   “d3c3bbbe0e”
 customize_changeset_uuid        “b92bc4d4-8665-49df-80ec-52ba9d8ec526”
 customize_autosaved     “on”
 customized
 ‘{“old_sidebars_widgets_data”:{“wp_inactive_widgets”:[“block-11”,“block-12”,“block-13”,“block-14”],“sidebar-1”:[“block-2”,“block-3”,“block-4”,“block-5”,“block-6”,“block-7”,“block-8”,“block-9”,“block-10”]},“nav_menu_locations[primary]”:3}’
 customize_changeset_status      “publish”
 action  “customize_save”
 customize_preview_nonce “bbf9d73816”
 }}}


 The JSON response returns:

 {{{
 {
   "success": false,
   "data": {
     "message": "Unable to save due to 1 invalid setting.",
     "code": "transaction_fail",
     "setting_validities": {
       "test_orphaned_setting": {
         "unrecognized": {
           "message": "Setting does not exist or is unrecognized.",
           "data": null
         }
       },
       "old_sidebars_widgets_data": true,
       "nav_menu_locations[primary]": true
     }
   }
 }
 }}}

 ⸻

 = Expected Behavior =
 Customizer should skip unrecognized (orphaned) settings left over from
 inactive plugins and allow the theme to be saved successfully.

 ⸻

 = Relevant Code =
 File: [https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-
 includes/class-wp-customize-manager.php#L1772-L1776 src/wp-includes/class-
 wp-customize-manager.php]

 == Original Code ==

 {{{#!php
 if ( isset( $stashed_theme_mods[ $stylesheet ] ) ) {
    $values = array_merge( $values, wp_list_pluck( $stashed_theme_mods[
 $stylesheet ], 'value' ) );
 }
 }}}

 == Proposed fix ==

 {{{#!php
 if ( isset( $stashed_theme_mods[ $stylesheet ] ) ) {
    $stashed_values = wp_list_pluck( $stashed_theme_mods[ $stylesheet ],
 'value' );

    $valid_stashed_values = array_filter( $stashed_values, function (
 $setting_id ) {
       return $this->get_setting( $setting_id );
    }, ARRAY_FILTER_USE_KEY );

    $values = array_merge( $values, $valid_stashed_values );
 }
 }}}

 = Additional Notes =

 This issue occurs because Customizer stashed theme mods may include
 references to settings that no longer exist after a plugin deactivation.
 The fix ensures only recognized settings are restored, preventing
 “unrecognized setting” errors and allowing the theme activation to
 complete successfully.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64231>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list