0

I'm trying to get a list of all theme mods / options currently registered. The normal way you can do it is to be inside the customizer, then $wp_customize->settings().

This will return a k,v pair of all the currenty registered theme mods that can, say, be saved.

If I inspect the global wp_customize outside the customizer itself, it's null, as expected.

Is there a workaround for this?

0

You don't need to fake being in the customizer, just grab the theme mods directly via get_theme_mods. Afterall they're just theme specific options.

Something like this would print out all the theme mods in a definition list:

function tomjn_print_theme_mods() {
    $mods = get_theme_mods();
    if ( empty( $mods ) {
        return;
    }
    echo '<dl>';
    foreach ( $mods as $k => $v ) {
        echo '<dt>'.esc_html( $k ).'</dt>';
        echo '<dd>'.esc_html( $v ).'</dd>';
    }
    echo. '</dl>';
}

https://codex.wordpress.org/Function_Reference/get_theme_mods

  • I thought so too, initially. But then you go ahead and inspect the settings() and you see way more things being there than in the $theme_name$_theme_mods option that get_theme_mods gives you. I have no idea how it works internally, I just know you must be inside the customizer to see these options. – Daniel Smith Oct 30 at 14:36
  • Then some of them might be options or generated, but I know for certain that what you're. trying to do is rare and unusual, and that there's no way to "fake" the customizer. Perhaps if you asked about the original task you were trying to achieve/solve rather than how to implement this solution I'd be able to give a more useful answer? – Tom J Nowell Oct 30 at 15:44
  • I frankly forgot. I feel bad for even asking. Been working for 16 hours now. The customizer has another type of theme mod that you can't see unless you go inside of it. If you could help with an idea, I will reword my question to fit that. – Daniel Smith Oct 30 at 19:04
  • hmmm do you have an example of that? It'd be good to try and reproduce it so I can figure out what it's doing – Tom J Nowell Oct 30 at 19: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.