Change setting name in Customizer and keep the data

Personally I think keeping your mods in an array is a nice solution, but transferring them shouldn’t be too difficult. Just loop through the array like this: $all_mods = get_theme_mod(‘thefunk_theme_options’); // retrieve array foreach ($all_mods as $key -> $value) { if (!empty($value)) set_theme_mod ($key,$value); // set array element as separate mod } Since you have … Read more

How Can I Create a List of Values to Be Iterated Through via WordPress Customization API?

Assuming you have an array $locations available, you can use this code to generate a dropdown in the customizer. It’s not that different from a single value. $section_name=”wpse213980_section_name”; // adapt to your naming system $section_title=”wpse213980_section_title”; // adapt to your naming system $setting_name=”wpse213980_setting_name”; // adapt to your naming system $setting_field_type=”select”; $setting_field_options = $locations; $sanitize_callback = ‘sanitize_text_field’; … Read more

How to hook CSS file according to theme selection in the customizer section

You can access Customizer values with get_theme_mod(), so you just need to check the value of your setting before enqueueing stylesheets the normal way: function wpse_310123_enqueue_scheme_css() { $scheme = get_theme_mod( ‘theme_scheme’ ); if ( $scheme === ‘green’ ) { wp_enqueue_style( ‘theme-green’, get_theme_file_uri( ‘green.css’ ) ); } elseif ( $scheme === ‘blue’) { wp_enqueue_style( ‘theme-blue’, get_theme_file_uri( … Read more

How to go about pre generating css file with variables from theme options

$ss_dir = get_stylesheet_directory(); // Shorten code, save 1 call ob_start(); // Capture all output (output buffering) require($ss_dir . ‘/library/css/dynamic.css.php’); // Generate CSS $css = ob_get_clean(); // Get generated CSS (output buffering) file_put_contents($ss_dir . ‘/library/css/static.css’, $css, LOCK_EX); // Save it Regards. PS: You cannot be a developer with scratchy files’ skills. They’re not optional.

Is it safe to post form data via Ajax to the settings api? Am I missing something?

WordPress does not natively use Ajax submits with Settings API, so there isn’t really best practice for it. I remember scbFramework having such option, but it was removed. Essentially there is nothing inherently more insecure to such submit, you should treat form data as untrusted regardless of submit method and appropriately sanitize and validate it … Read more

WordPress site migration addvice

First of all. You don’t need to use plugins in order to migrate some wordpress from one place from another. 1) Make backups. When you have a backup with, for example Updraft you can easily make backup with all things, and restore backup. 2) Hard migration. Best migration. I am doing this type of migration … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)