lundi 29 juin 2020

Can I use a Class/Methods to run through an array of WP Customizer settings to register them?

I have an array of WordPress Theme Customizer settings that I want to register and output to the Theme Customizer, and they all register fine, and they all work perfectly.

This is where my problem is, $wp_customize->add_setting won't seem to pass the Theme Checker plugins' checks, it doesn't seem to like using a variable in place of an ID for the setting, even though the variable contains the setting name. When I'm looping through the array I have, everything works fine in the Theme Customizer (all settings, control, sections and panels that I'm registering are there, and working and updating and even refreshes in the preview window), but in the Theme Checker plugin, I get this error repeated 100's of times when the tests are run:

Warning: preg_match(): No ending delimiter '$' found in I:\xampp\htdocs\basic\wp-content\plugins\theme-check\checkbase.php on line 110

The line that is causing the problem is the one that registers the settings:

$wp_customize->add_setting( $set_name, $items['setting'] );

The "ending delimiter" that it's referring to is for the $set_name, but I can't find a way of passing this without these errors appearing, even though the functionality of the Theme is working perfectly. Is there some sort of way that I can make the add_setting() method take my variable which holds my setting name?

The tests do complete, and it shows this related to the problem:

REQUIRED: Found a Customiser setting called $set_name in theme-customizer.php that did not have a sanitisation callback function. Every call to the add_setting() method needs to have a sanitisation callback function passed.

It seems to be passing the literal variable name, rather than it's contents, however, the Customizer functions as expected, and registers/saves the settings in the correct names that I've given in the array of settings.

Can anyone help please?

Aucun commentaire:

Enregistrer un commentaire