Wordpress Customizer keeps hiding custom sections - php

I have custom plugin that adds Customizer sections and options.
The sections can be seen briefly on the customizer screen but then disappear. This behavior is happening on all themes (I am using my plugin on other sites).
Maybe it might be because the setting fields are not used in the theme yet, but even if I create my own theme (for which this plugin is mainly used) and add echo get_theme_mod('setting-key') somewhere in the themes code, the sections are still being hidden by wordpress.
I have clean Wordpress install version 5.2.2, using default Twenty Nineteen theme with only jQuery updater plugin active. I have checked all JS code for potential errors and any hiding happening, but nothing on my part can be causing this.
This is how I am adding sections, in customize_register hook:
add_action('customize_register', 'setup_section');
function setup_section($wp_customize){
// Add section
$wp_customize->add_section('section_id', array(
'title' => 'Section Title',
'priority' => 160,
));
// Add settings for a field
$wp_customize->add_setting('setting_id', array(
'default' => '',
'transport' => 'refresh',
));
// Add the field into a section and assign setting id
$wp_customize->add_control('setting_id', array(
'label' => 'Option Label',
'section' => 'section_id',
'settings' => 'setting_id',
'type' => 'text',
));
}
The PHP code is working as expected, but after the page loads, all my custom sections get display: none; inline css added and the sections disappear.
Any help is appreciated.

Another reason why the custom sections kept hidden is when they don't have any controls. When a section is empty WordPress hides it by default.
Here's a full working piece of code for adding a section within Customizer with one control:
function mytheme_customize_register( $wp_customize ) {
$wp_customize->add_section('footer_settings_section', array(
'title' => 'Footer Text Section'
));
$wp_customize->add_setting('text_setting', array(
'default' => 'Default Text For Footer Section',
));
$wp_customize->add_control('text_setting', array(
'label' => 'Footer Text Here',
'section' => 'footer_settings_section',
'type' => 'textarea',
));
}
add_action( 'customize_register', 'mytheme_customize_register' );

Related

Update user repeater meta (ACF) with another user meta field value

My goal is to get a signed-in user to select a color( via front end form and saved in ACF user meta field group) that will be applied to another user meta field inside a repeater. The field must be the same for each row inside the repeater ( for front-end design reasons ). I am using ACF pro, and a plugin called ACF Front end admin (let's call it FEA from now on) for the front-end form. I'm pretty new to PHP and have referenced ACF & FEA's s documentation, which can be found below, spin up a custom function. I am currently running this through the code snippets plugin if this helps. I've run an error log and nothing related to this shows. Tried running this through wp-config and it crashes my site.
Front end admin documentation
ACF documentation - update sub field
ACF documentation - getting values from a user
Edit, Additional information:
ACF Field composition of 'button color' (color of the buttons that user wants displayed in front end, and saved as user meta):
acf_add_local_field_group(array(
'key' => 'group_60000aaa00000',
'title' => 'Color Selector',
'fields' => array(
array(
'key' => 'field_60000aaa00000',
'label' => 'Button color',
'name' => 'button_color',
'type' => 'color_picker',
Button color in repeater field that needs to updated based on the above mentioned 'button_color' meta value:
acf_add_local_field_group(array(
'key' => 'group_70000bbb00000',
'title' => 'front end user profile',
'fields' => array(
array(
'key' => 'field_70000bbb00000',
'label' => 'Quick Link selector',
'name' => 'quick_link_selector',
'type' => 'repeater',
),
array(
'key' => 'field_70000ccc00000',
'label' => 'repeater button color',
'name' => 'repeater_button_color',
'type' => 'text',
The title of the forum is: "QL color selector form" (created through the FEA plugin) and has a short code of [frontend_admin form="3030"] if this helps.
I'm running the following code with no luck and would really appreciate any help!
/// Hooks into any(?) form and does something
add_action('acf_frontend/save_user', 'retrieve_colors_2_update', 10, 2);
function retrieve_colors_2_update( $form, $user_id ) {
$user = get_user_by('ID',$user_id);
//get important fields
$btn_color = get_field('button_color', 'user_' .$user_id);
//// update a repeater loop (ACF)
if( have_rows('quick_link_selector', 'user_'.$user_id) ) {
$i = 0;
while( have_rows('quick_link_selector') ) {
the_row();
$i++;
update_sub_field('repeater_button_color', $btn_color );
}
}
}

Wordpress - Add case studies then link 3 onto homepage

I am new to wordpress so sorry for the basic question. How do I have a case studies page, but link 3 case studies to display a shortened version onto my homepage.
Any ideas?
Thanks!
Scott
I would start by creating a Custom Post Type called case studies. Add the following to your theme's (or child theme) function.php.
// Create Custom Post Type
function my_custom_posttype(){
register_post_type('case studies',
// Options
array(
'labels' => array(
'name' => __('Case Studies'),
'singular_name' => __('Case Study')
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'case-studies'),
)
);
}
add_action( 'init', 'my_custom_posttype' );
This will add a new link in the admin to add new case studies, just like posts and pages. This is a very basic example, check the link above for more information on post types.
Adding them into the homepage will depend on what theme you are using.

WordPress theme behaving bad

Hope you all are doing great since last few days i am facing an issue with my WordPress site this is a plugin or theme i am not sure but the file is in theme which throws error of undefined function
because of this error i am not able to open my customize menu from wordpress admin panel
and once i commented the code line where this code exists it start working but widgets does not work properly like if i enable social icons in widgets i wont be able to disable them and save settings here is the code i have commented.
$jobcareer_opt_array = array(
'name' => esc_html__('Title', 'jobcareer'),
'desc' => '',
'hint_text' => '',
'echo' => true,
'field_params' => array(
'std' => esc_attr($jobcareer_widget_title),
/*'id' => cs_allow_special_char($this-
>get_field_id('title')),*/
'classes' => '',
/*'cust_id' => cs_allow_special_char($this-
>get_field_name('title')),*/
/*'cust_name' => cs_allow_special_char($this-
>get_field_name('title')),*/
'return' => true,
'required' => false
),
);
May be there is some version conflict between the theme and Codestar plugin. You can ask your theme's developer for that. Or as a temporary solution just remove cs_allow_special_char function and use its parameter insteaad. For example replace
cs_allow_special_char($this->get_field_name('title'))
with
$this->get_field_name('title')
and it should work then.
I checked the plugin's source, that function doesn't do any critical operation:
function cs_allow_special_char($input = ''){
$output = $input;
return $output;
}

How can I put in a proper image path URL for radio button options in my Wordpress Child Theme Customizer?

I've been working on this for a while and even though i've searched through a lot of stackoverflow questions/answers, i haven't been able to find what i'm looking for.
My question:
I'm working on developing my first genesis wordpress child theme, particularly now the customizer. I want the user to be able to have different options, one of which is choosing from a few background patterns that I've designed for a certain div class. There are three different patterns, and I've been able to so far make three radio buttons. Here is the code:
$wp_customize->add_setting('BG_Pattern', array( 'default' => '#f5ebdf',));
$wp_customize->add_control('BG_Pattern', array(
'label' => __('Background Pattern', 'FoxiePro'),
'section' => 'backgrounds',
'settings' => 'BG_Pattern',
'type' => 'radio',
'choices' => array(
'tan.jpg' => 'Tan',
'#e6e6e6' => 'gray',
'teal' => 'teal',
),
));
And the output is this, in the header.php file:
<?php
$BG_Pattern = get_theme_mod('BG_Pattern');
?>
<style>
.enews-widget {background-image: url( '<?php echo $BG_Pattern; ?>' );}
</style>
Where it says "tan.jpg", is where I would like to put in a url to tan.jpg src, which is in my child theme folder. However, any link I put in doesn't make the pattern appear. Inputting something like:
'bloginfo('template_url'); ?>/images/tan.jpg' => 'Tan',
also hasn't worked for me. Anyone have any ideas? Thanks!
Figured it out, because it's a child theme, needed to use the following:
get_stylesheet_directory_uri() . '/images/backgrounds/tan.jpg' => 'Tan',

The parameter ‘path’ is required. in my functions.php file

Hi guys so I have been working on my functions.php page for a custom Wordpress theme of mine and can't figure out the issue... It is something between lines 0 - 10... Some things I have read relate it to the get_stylesheet_uri() Please help... I am only new to Wordpress and can't figure this out...
<?php
function asns_resources() {
wp_enqueue_style('style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'asns_resources');
//Custom Appearance
function allsugar_customise_register( $wp_customize ){
$wp_customize->add_setting('asns_link_colour', array(
'default' => '#f4f4f8',
'transport' => 'refresh',
));
$wp_customize->add_section('asns_standard_colours', array(
'title' => __('Standard Colours', 'AllSugar-NoSpice'),
'priority' => 30,
));
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'asns_link_colour_control', array(
'label' => __('Link Colour', 'AllSugar-NoSpice'),
'section' => 'asns_standard_colours',
'settings' => 'asns_link_colour',
) ) );
}
add_action('customize_register', 'allsugar_customise_register');
?>
I have experienced that before. Only it was when editing via the cPanel File Manager.
I found the cause of the problem was that I had changed the name of the file/folder after I had already opened the file to edit it.
All I had to do was copy the contents of the file to the clipboard then close the tab in the browser and just re-access that same file again and then paste the code with all the changes I had made before and VOILA!! It successfully saved and "The parameter ‘path’ is required" error was gone.

Categories