0

I've renamed my theme folder and all other title related bits, but I had a long list of settings and controls that were added with labels related to the old name, I want to remove these.

I believe I'm doing it correctly with the following:

function remove_settings_controls($wp_customize) {

    $wp_customize->remove_setting('psychic2016_logo');
    $wp_customize->remove_control('psychic2016_logo');

    $wp_customize->remove_setting('psychic2016_facebook');
    $wp_customize->remove_control('psychic2016_facebook');

    $wp_customize->remove_setting('psychic2016_twitter');
    $wp_customize->remove_control('psychic2016_twitter');

    $wp_customize->remove_setting('psychic2016_google_profile');
    $wp_customize->remove_control('psychic2016_google_profile');

    $wp_customize->remove_setting('psychic2016_google_analytics');
    $wp_customize->remove_control('psychic2016_google_analytics');

    $wp_customize->remove_setting('psychic2016_xml_id');
    $wp_customize->remove_control('psychic2016_xml_id');

    $wp_customize->remove_setting('psychic2016_xml_overflow');
    $wp_customize->remove_control('psychic2016_xml_overflow');

    $wp_customize->remove_setting('psychic2016_geoip_default');
    $wp_customize->remove_control('psychic2016_geoip_default');

    $wp_customize->remove_setting('psychic2016_geoip_status');
    $wp_customize->remove_control('psychic2016_geoip_status');

    $wp_customize->remove_setting('psychic2016_psychics_url');
    $wp_customize->remove_control('psychic2016_psychics_url');

    $wp_customize->remove_setting('psychic2016_offers');
    $wp_customize->remove_control('psychic2016_offers');

    $wp_customize->remove_setting('psychic2016_click2call');
    $wp_customize->remove_control('psychic2016_click2call');

    $wp_customize->remove_setting('psychic2016_prem');
    $wp_customize->remove_control('psychic2016_prem');

    $wp_customize->remove_setting('psychic2016_prem_badge');
    $wp_customize->remove_control('psychic2016_prem_badge');

    $wp_customize->remove_setting('psychic2016_sms');
    $wp_customize->remove_control('psychic2016_sms');

    $wp_customize->remove_setting('psychic2016_webchat_url');
    $wp_customize->remove_control('psychic2016_webchat_url');

    $wp_customize->remove_setting('psychic2016_webcam_url');
    $wp_customize->remove_control('psychic2016_webcam_url');

    $wp_customize->remove_setting('psychic2016_webcam_ID');
    $wp_customize->remove_control('psychic2016_webcam_ID');

    $wp_customize->remove_setting('psychic2016_click2call_url');
    $wp_customize->remove_control('psychic2016_click2call_url');

    $wp_customize->remove_setting('psychic2016_sms_url');
    $wp_customize->remove_control('psychic2016_sms_url');

    $wp_customize->remove_setting('psychic2016_featured_image_full');
    $wp_customize->remove_control('psychic2016_featured_image_full');

    $wp_customize->remove_setting('psychic2016_recaptcha_site_key');
    $wp_customize->remove_control('psychic2016_recaptcha_site_key');

    $wp_customize->remove_setting('psychic2016_recaptcha_secret_key');
    $wp_customize->remove_control('psychic2016_recaptcha_secret_key');

    $wp_customize->remove_setting('psychic2016_categories_clairvoyant');
    $wp_customize->remove_control('psychic2016_categories_clairvoyant');

    $wp_customize->remove_setting('psychic2016_categories_clairsentient');
    $wp_customize->remove_control('psychic2016_categories_clairsentient');

    $wp_customize->remove_setting('psychic2016_categories_clairaudient');
    $wp_customize->remove_control('psychic2016_categories_clairaudient');

    $wp_customize->remove_setting('psychic2016_categories_life_coach');
    $wp_customize->remove_control('psychic2016_categories_life_coach');

    $wp_customize->remove_setting('psychic2016_categories_counsellor');
    $wp_customize->remove_control('psychic2016_categories_counsellor');

    $wp_customize->remove_setting('psychic2016_categories_medium');
    $wp_customize->remove_control('psychic2016_categories_medium');

    $wp_customize->remove_setting('psychic2016_categories_psychic');
    $wp_customize->remove_control('psychic2016_categories_psychic');

    $wp_customize->remove_setting('psychic2016_categories_reiki_healer');
    $wp_customize->remove_control('psychic2016_categories_reiki_healer');

    $wp_customize->remove_setting('psychic2016_categories_wicca');
    $wp_customize->remove_control('psychic2016_categories_wicca');

    $wp_customize->remove_setting('psychic2016_subjects_love_relationship');
    $wp_customize->remove_control('psychic2016_subjects_love_relationship');

    $wp_customize->remove_setting('psychic2016_subjects_career_work');
    $wp_customize->remove_control('psychic2016_subjects_career_work');

    $wp_customize->remove_setting('psychic2016_subjects_pets_animals');
    $wp_customize->remove_control('psychic2016_subjects_pets_animals');

    $wp_customize->remove_setting('psychic2016_subjects_destiny_life_path');
    $wp_customize->remove_control('psychic2016_subjects_destiny_life_path');

    $wp_customize->remove_setting('psychic2016_subjects_past_lives');
    $wp_customize->remove_control('psychic2016_subjects_past_lives');

    $wp_customize->remove_setting('psychic2016_subjects_deceased_loved_ones');
    $wp_customize->remove_control('psychic2016_subjects_deceased_loved_ones');

    $wp_customize->remove_setting('psychic2016_tools_angel_cards');
    $wp_customize->remove_control('psychic2016_tools_angel_cards');

    $wp_customize->remove_setting('psychic2016_tools_astrology');
    $wp_customize->remove_control('psychic2016_tools_astrology');

    $wp_customize->remove_setting('psychic2016_tools_crystals');
    $wp_customize->remove_control('psychic2016_tools_crystals');

    $wp_customize->remove_setting('psychic2016_tools_numerology');
    $wp_customize->remove_control('psychic2016_tools_numerology');

    $wp_customize->remove_setting('psychic2016_tools_oracle_cards');
    $wp_customize->remove_control('psychic2016_tools_oracle_cards');

    $wp_customize->remove_setting('psychic2016_tools_pendulum');
    $wp_customize->remove_control('psychic2016_tools_pendulum');

    $wp_customize->remove_setting('psychic2016_tools_runestones');
    $wp_customize->remove_control('psychic2016_tools_runestones');

    $wp_customize->remove_setting('psychic2016_tools_tarot_cards');
    $wp_customize->remove_control('psychic2016_tools_tarot_cards');

}
add_action('customize_register', 'remove_settings_controls', 1000);

However, when I re-load the frontend, I expect there to be loads of errors from the calls within the template files to get_theme_mod() where these settings will no longer return anything, but nothing has changed.

Even if I var_dump(get_theme_mod('psychic2016_xml_id')) right underneath the above function, I get the value that was stored printed.

In the WP admin customizer, none of the previous controls are showing, so although the options have been removed, the values are still stored, which should have been deleted.

Why haven't they been removed as per the function above?

Any help is greatly appreciated.

0

In the WP admin customizer, none of the previous controls are showing, so although the options have been removed, the values are still stored, which should have been deleted.

You haven't done anything to delete them. The code in your question will remove the registered controls from the customiser, and the registered settings, but you need to consider what that means.

When you add a setting to the Customiser with add_setting() what you're doing is registering various behaviours around saving that setting. Things like controlling which users have permission to save it, and how the setting values should be sanitised.

So when you remove a setting from the Customiser, you are just removing those behaviours, and deregistering any controls that interact with that setting. It's the opposite of add_setting(), and you'll note that add_setting() does not save anything to the database.

This is all about the behaviour of the Customiser interface itself. None of this has anything to do with the actual data that's saved in the database. Once that data's saved in the database it's there until you delete it. The get_theme_mod() function does not interact with the Customiser in any way. It simply retrieves the value from the database directly. This is why get_theme_mod() does not return any default value set with add_setting(), and it's why it's still returning values for unregistered settings.

If you want to remove a saved theme mod, you need to use remove_theme_mod():

remove_theme_mod( 'psychic2016_logo' );

But note you will only need to run this code once and the value will be permanently deleted (The customize_register hook runs every time the Customiser is loaded).

  • Thanks for that, that makes sense. So if I were to add a remove_theme_mod() to the function above for each group, and re-load the site on front end, this would clear all the values? – Lee Feb 20 at 11:45
  • You'd need to reload the Customiser once, then that would clear the values. I don't believe the customize_register hook runs on the front-end. – Jacob Peattie Feb 20 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.