WordPress customizer multiple add_control 's in section - wordpress

Quick question.
I'm trying to add multiple controls within a WordPress customizer section.
$wp_customize->add_section( 'lr_panel2', array(
'title' => esc_html__( 'Panel 2', 'lr' ),
'active_callback' => 'is_front_page',
'panel' => 'lr_theme_options',
'description' => esc_html__( 'Add a background image to your panel by setting a featured image in the page editor. If you don’t select a page, this panel will not be displayed.', 'lr' ),
) );
$wp_customize->add_setting( 'lr_panel2', array(
'default' => false,
'sanitize_callback' => 'lr_sanitize_numeric_value',
) );
$wp_customize->add_control( 'lr_panel2', array(
'label' => esc_html__( 'Panel Content', 'lr' ),
'section' => 'lr_panel2',
'type' => 'dropdown-pages',
) );
So this one is working fine and dandy. I try to add a second one and neither render. I assumed I could just repeat the add_control class, something like:
$wp_customize->add_control( 'lodestar_panel2', array(
'label' => esc_html__( 'Panel Layout', 'lr' ),
'section' => 'lr',
'type' => 'select',
'choices' => array(
),
) );
But that's not working how I want it too, Has anyone done this before?
Thanks!

You are adding the control in another section. Section should be same
'section' => 'lr_panel2',
This is the section of first control you've added and
'section' => 'lr',
This is the section of second control you've added
Also a control wouldn't show unless you've added somethings in it.

Related

How will i add an option under customizer woocommerce section?

What is the customizer section name? I want to add a field option under customizer woocommerce section. Or how will I add a field under woocommerce option? Can someone help me with that?
$wp_customize->add_section( 'woocommerce_secction_name' , array(
'title' => __( 'My Section Name', 'starter' ),
'priority' => 30
) );
$wp_customize->add_setting( 'starter_new_setting_name' , array(
'default' => '#000000',
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
'label' => __( 'Header Color', 'starter' ),
'section' => 'woocommerce_secction_name',
'settings' => 'starter_new_setting_name',
) ) );
// Add section to WooCommerce Panel
$wp_customize->add_section( 'SECTION_NAME',
array(
'title' => __( 'SECTION TITLE'),
'panel' => 'woocommerce',
'capability' => '',
'priority' => 500,
)
);
The important part is the panel name as you can see selecting woocommerce it will add to the woocomerce panel

Wordpress How Can I Display skill1_logo in View

Hi Im practically a newbie and would like to kindly ask how can I display skill1_logo,skill1_title,skill1_description on a page that I want. I was trying to do a 1 page website using wordpress to practice my wordpress.
function theme_skills_customizer($wp_customize){
//adding section in wordpress customizer
$wp_customize->add_section('skills_settings_section', array(
'title' => 'Skills Section'
));
$wp_customize->add_setting('skill1_logo');
$wp_customize->add_setting('skill1_title');
$wp_customize->add_setting('skill1_description');
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'skill1_logo', array(
'label' => __( 'Skill 1 Logo', 'themeslug' ),
'width' => 400,
'height' => 400,
'flex-width' => true,
'flex-height' => true,
'section' => 'skills_settings_section',
'settings' => 'skill1_logo',
)));
$wp_customize->add_control( 'skill1_title', array(
'label' => __( 'Skill 1 Title' ),
'section' => 'skills_settings_section', // Add a default or your own section
'type' => 'text',
));
$wp_customize->add_control( 'skill1_description', array(
'label' => __( 'Skill 1 Description' ),
'section' => 'skills_settings_section', // Add a default or your own section
'type' => 'textarea',
));
}
add_action( 'customize_register', 'theme_skills_customizer' );
You can use get_theme_mod function to echo those settings.
e.g.
$s_title = get_theme_mod('skill1_title');

Visual Composer custom markup for custom shortcode (vc_map)

Trying to get custom_markup to work with the Visual Composer builder for WordPress.
Found Visual Composer change custom shortcode template and also Visual Composer custom shortcode template - custom_markup display user input but none of them has an answer.
Here's some documentation for the vc_map function https://wpbakery.atlassian.net/wiki/pages/viewpage.action?pageId=524332
Here's my shortcode that I'm using, everything works perfectly, it just looks horrible in the backend ui
vc_map( array(
"name" => "example",
"base" => "adwise_vc_example",
"class" => "",
"category" => "Plugin name",
"icon" => "awm_vc_icon",
"custom_markup" => load_template( ADWISE_VC_DIR . '/vc_templates/adwise_example.php', false),
"params" => array();
Which currently looks like --> https://dl.dropboxusercontent.com/u/11204765/SS/mac/Screen%20Shot%202016-05-02%20at%2012.52.56.png
In the example below I've tried to set custom_markup to test
which results in https://dl.dropboxusercontent.com/u/11204765/SS/mac/Screen%20Shot%202016-05-02%20at%2012.45.55.png
vc_map( array(
"name" => "example",
"base" => "adwise_vc_example",
"class" => "",
"category" => "Plugin name",
"icon" => "awm_vc_icon",
"custom_markup" => "test",
"params" => array();
My primary/main problem is that I don't know how to get the values of each attribute for each shortcode to display in the template file.
I've looked almost everywhere for a solution, including browsing through other Visual Composer plugins to see how they've accomplished this.
Any help would be greatly appreciated!
What are you trying to accomplish exactly ? From the visual composer core code this is the custom markup for the tabs
'custom_markup' => '
<div class="wpb_tabs_holder wpb_holder vc_container_for_children">
<ul class="tabs_controls">
</ul>
%content%
</div>',
So maybe something like %customattr% will get your desired result?
just add an array with the shortcode attributes in 'params'
'params' => array(
array(
'type' => 'textfield',
'holder' => 'div',
'class' => '',
'heading' => __( 'Title' ),
'param_name' => 'title',
'value' => __( 'Titre' ),
'description' => __( 'Title' ),
),
array(
'type' => 'textarea',
'holder' => 'div',
'class' => '',
'heading' => __( 'Description' ),
'param_name' => 'desc',
'value' => __( 'description' ),
'description' => __( 'Description' ),
),
array(
'type' => 'attach_image',
'holder' => 'img',
'class' => '',
'heading' => __( 'Image' ),
'param_name' => 'img_url',
'value' => __( '' ),
'description' => __( 'Image' ),
),
)
and if you want hide a section in the backend just remove the 'holder' line

retrieve customize_register setting from wordpress

I'm trying to retrieve some customizer settings that I initiated.
function notop_customize_register( $wp_customize ) {
$wp_customize->add_section( 'header_images', array(
'title' => 'Header Images',
'priority' => 2,
'description' => "Add images with links to be redirected to when the images are clicked",
) );
// Add color scheme setting and control.
$wp_customize->add_setting( 'header_image_1_setting', array(
'capability' => 'edit_theme_options',
'type' => 'option',
) );
$wp_customize->add_control(new WP_Customize_Upload_Control($wp_customize,'header_image_1_control', array(
'label' => __( 'Import Image', 'notop' ),
'section' => 'header_images',
'settings' => 'header_image_1_setting',
) ) );
}
add_action( 'customize_register', 'notop_customize_register' );
How do I get the url of header_image_1?
I thought it might be get_theme_mod('header_image_1_setting'); but that hasn't worked so far. Also, I'm not sure if I'm actually supposed to call the customize_register file in my index somewhere or if it's okay the way it is.
cale_b's comment is the answer.
get_option('header_image_1_setting')
=> http://...

Implementing A WordPress Settings Class for Options Pages

I'm trying to implement this class: A WordPress Settings Class for Options Pages
What I tried:
function add_wp_page(){
require_once( TEMPLATEPATH."/folder_admin/wm-settings.php" );
// A top level page
$my_top_page = create_settings_page(
'my_top_level_page',
__( 'My Top Level Page' ),
array(
'parent' => false,
'title' => __( 'Top Level Menu' ),
'icon_url' => 'dashicons-admin-generic',
'position' => '63.3'
),
array(
'my_standard_section' => array(
'title' => __( 'Standard' ),
'description' => __( 'My section description.' ),
'fields' => array(
'my_input' => array(
'label' => __( 'Input example' )
),
'my_checkbox' => array(
'type' => 'checkbox',
'label' => __( 'Checkbox example' )
),
'my_textarea' => array(
'type' => 'textarea',
'label' => __( 'Textarea example' )
)
)
)
),
array(
'tabs' => true,
'submit' => __( 'My Submit' ),
'reset' => __( 'My reset' ),
'description' => __( 'My page description.' ),
'updated' => __( 'My success message !')
)
);
// And a sub-page
$my_sub_page = create_settings_page(
'my_sub_page',
__( 'My Sub Page' ),
array(
'parent' => 'my_top_level_page',
'title' => __( 'Sub Level Menu' )
)
);
}
add_action( 'admin_init', 'add_wp_page' );
The TEMPLATEPATH is it ok. If I echo something in wp-settings.php it will print it.
The rest of the code it is from that website. It is from an example.
The menu doesn't show.
Am I missing something?
Thanks
The settings need to be registered before 'admin_init'.
Replace the last line with add_action( 'init', 'add_wp_page' );.
Also, avoid wrapping the require_once in an action or you won't be able to access get_setting() outside your hook.
Oh, and the position can be a string. And it is actually recommended to use a decimal number to prevent possible conflicts for these menu positions with other plugins or themes.
Please set a 'position' => '63.3' to integer.
or use positions of core menu:
2 Dashboard
4 Separator
5 Posts
10 Media
15 Links
20 Pages
25 Comments
59 Separator
60 Appearance
65 Plugins
70 Users
75 Tools
80 Settings
99 Separator
The position in the menu order this menu should appear.
Hope it solves your problems :)

Resources