WordPress: How to use active callbacks in the Customizer - php

In my theme, I set up 2 options use Theme Customization API, the code snippet below.
I want to display the radio option when the checkbox is true, when the checkbox is false, the radio hidden. I try to use active_callbackļ¼Œbut not working. So, How can achieve this function?
Thanks!
// Related Post.
$wp_customize->add_setting('_related_post', array(
'capability' => 'edit_theme_options',
'default' => 0,
'transport' => 'postMessage',
));
$wp_customize->add_control('_related_post', array(
'settings' => '_related_post',
'label' => __('Display Related Posts', 'typenow'),
'section' => '_theme_options',
'type' => 'checkbox',
'priority' => 30,
));
// Related Post Num.
$wp_customize->add_setting('_related_post_num', array(
'capability' => 'edit_theme_options',
'default' => '2',
'transport' => 'postMessage',
));
$wp_customize->add_control('_related_post_num', array(
'settings' => '_related_post_num',
'label' => __('Related Posts Number', 'typenow'),
'section' => '_theme_options',
'type' => 'radio',
'priority' => 35,
'choices' => array (
'2' => __('Two posts', 'typenow'),
'4' => __('Four posts', 'typenow'),
),
));

The solution:
$wp_customize->add_control('_related_post_num', array(
'settings' => '_related_post_num',
'label' => __('Related Posts Number', 'typenow'),
'section' => '_theme_options',
'type' => 'radio',
'priority' => 35,
'choices' => array (
'2' => __('Two posts', 'typenow'),
'4' => __('Four posts', 'typenow'),
),
'active_callback' => function(){
return get_theme_mod( '_related_post', false );
},
));

Related

add acf filed to admin_menu programmatically

can we add ACF fields to custom admin_menu page?
so I have created an admin page as shown
add_action( 'admin_menu', 'opt_add_admin_menu' );
function opt_add_admin_menu( ) {
add_menu_page( 'opt', 'opt', 'manage_options', 'opt', 'opt_options_page' );
}
so next I need to add an ACF field to this options page
I got this code from ACF but the location still makes a problem for me
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_6335ef4ab316e',
'title' => 'justfortest',
'fields' => array(
array(
'key' => 'field_6335ef5351c1c',
'label' => 'text',
'name' => 'text',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
'location' => array(
array(
array(
'param' => 'post_type', /* here we need to target the menu options page */
'operator' => '==',
'value' => 'post', /* here to */
),
),
),
I know how to add fields programmatically without ACF but if there is a way to add through ACF it will be so helpful
Create new admin page using acf option page
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'opt',
'menu_title' => 'opt',
'menu_slug' => 'opt-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}
and select option page ->opt while adding new group
--- You need acf pro version to use this feature

Storefront overwrite customize register?

I am creating a child theme using the storefront as a parent theme so far I am doing well, I am trying to create a website where I can change the basic aspects of the style of the website like background-color, custom text in wp-admin/customize.php.
I know I can add more options using customize_register , but the storefront theme has its own action hook for that, in fact I already added my own action hook to enable more options see below
as you can see the problem is that it creates another "footer" option, is there any way to overwrite or insert custom options, within the existing "footer" option of the parent theme?
here the code im using to insert options
function footer_customize_register( $custom_vars ) {
$custom_vars ->add_section(
'layout_section',
array(
'title' => __( 'Footer', 'pre' ),
'capability' => 'edit_theme_options',
'description' => __( 'Allows you to edit your theme layout.', 'pre' ),
'priority' => 25,
)
);
$custom_vars -> add_setting('pre_layout_options[address_text]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
'default' => '000 7th St NW',
));
$custom_vars -> add_control('pre_layout_options[address_text]', array(
'label' => 'adress',
'section' => 'layout_section',
'type' => 'text',
));
$custom_vars -> add_setting('pre_layout_options[phone_text]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
'default' => '01234-567',
));
$custom_vars -> add_control('pre_layout_options[phone_text]', array(
'label' => 'ZIP code',
'section' => 'layout_section',
'type' => 'text',
));
$custom_vars -> add_setting('pre_layout_options[VAT]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
'default' => '00.000.000/0000-00',
));
$custom_vars -> add_control('pre_layout_options[VAT]', array(
'label' => 'VAT number',
'section' => 'layout_section',
'type' => 'text',
));
$custom_vars -> add_setting('pre_layout_options[Location]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
'default' => 'Centro',
));
$custom_vars -> add_control('pre_layout_options[Location]', array(
'label' => 'Location',
'section' => 'layout_section',
'type' => 'text',
));
}
add_action('customize_register', 'footer_customize_register');
the source code is from here
in section you need to add storefront_footer and add priority to change position. check below code.
function footer_customize_register( $custom_vars ) {
$custom_vars -> add_setting('pre_layout_options[address_text]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
'default' => '000 7th St NW',
));
$custom_vars -> add_control('pre_layout_options[address_text]', array(
'label' => 'adress',
'section' => 'storefront_footer',
'type' => 'text',
'priority' => 50,
));
$custom_vars -> add_setting('pre_layout_options[phone_text]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
'default' => '01234-567',
));
$custom_vars -> add_control('pre_layout_options[phone_text]', array(
'label' => 'ZIP code',
'section' => 'storefront_footer',
'type' => 'text',
'priority' => 60,
));
$custom_vars -> add_setting('pre_layout_options[VAT]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
'default' => '00.000.000/0000-00',
));
$custom_vars -> add_control('pre_layout_options[VAT]', array(
'label' => 'VAT number',
'section' => 'storefront_footer',
'type' => 'text',
'priority' => 70,
));
$custom_vars -> add_setting('pre_layout_options[Location]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
'default' => 'Centro',
));
$custom_vars -> add_control('pre_layout_options[Location]', array(
'label' => 'Location',
'section' => 'storefront_footer',
'type' => 'text',
'priority' => 80,
));
}
add_action('customize_register', 'footer_customize_register');
Tested and works.

How to add custom theme features of post into custom post type? Wordpress, php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
i created a custom post type but i only get default support features like thumbnails, exerpt etc but what i want is to add all extra features of ceris theme in posts into my custom post type can you help me out?
$args = array(
'label' => __( 'directory', 'Ceris' ),
'description' => __( 'directory all posts', 'Ceris' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'editor', 'excerpt','thumbnail', 'comments', 'revisions', 'custom-fields','post-formats','page-attributes','bk_review_score' ),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies' => array( 'posts' ),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'show_in_rest' => true,
);
check my support array like i'm trying to add bk_review_system into my cpt
yes you can do it
try the following code, BK come with a filter to add widget and there configuration
function bk_child_register_meta_boxes($meta_boxes) {
$meta_boxes[] = array(
'id' => 'bk_review',
'title' => esc_html__( 'BK Review System', 'ceris' ),
'pages' => array( 'directory' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'type' => 'heading',
'name' => esc_html__('Author Review', 'ceris'),
'desc' => esc_html__('This section allow you to give your review, pros, cons', 'ceris'),
),
// Enable Review
array(
'name' => esc_html__( 'Review Box', 'ceris' ),
'id' => 'bk_review_checkbox',
'type' => 'checkbox',
'desc' => esc_html__( 'Enable Review On This Post', 'ceris' ),
'std' => 0,
),
array(
'visible' => array( 'bk_review_checkbox', '=', 1),
'type' => 'divider',
),
array(
'id' => 'bk_review_box_position',
'name' => esc_html__( 'Review Box Position', 'ceris' ),
'type' => 'select',
'options' => array(
'default' => esc_html__( 'Default -- Under the post content', 'ceris' ),
'top' => esc_html__( 'On top of the post content ', 'ceris' ),
),
// Select multiple values, optional. Default is false.
'multiple' => false,
'std' => 'default',
'visible' => array( 'bk_review_checkbox', '=', 1),
),
array(
'visible' => array( 'bk_review_checkbox', '=', 1),
'type' => 'divider',
),
array(
'name' => 'Product Image',
'id' => 'bk_review_product_img',
'type' => 'single_image',
'visible' => array( 'bk_review_checkbox', '=', 1),
),
array(
'name' => esc_html__( 'Product name', 'ceris' ),
'id' => 'bk_review_box_title',
'type' => 'textarea',
'cols' => 20,
'rows' => 2,
'visible' => array( 'bk_review_checkbox', '=', 1),
),
array(
'name' => esc_html__( 'Description', 'ceris' ),
'id' => 'bk_review_box_sub_title',
'type' => 'textarea',
'cols' => 20,
'rows' => 2,
'visible' => array( 'bk_review_checkbox', '=', 1),
),
array(
'visible' => array( 'bk_review_checkbox', '=', 1),
'type' => 'divider',
),
//Review Score
array(
'name' => esc_html__( 'Review Score', 'ceris' ),
'id' => 'bk_review_score',
'class' => 'ceris-',
'type' => 'slider',
'visible' => array( 'bk_review_checkbox', '=', 1),
'js_options' => array(
'min' => 0,
'max' => 10.05,
'step' => .1,
),
),
array(
'visible' => array( 'bk_review_checkbox', '=', 1),
'type' => 'divider',
),
// Summary
array(
'name' => esc_html__( 'Summary', 'ceris' ),
'id' => 'bk_review_summary',
'type' => 'textarea',
'cols' => 20,
'rows' => 4,
'visible' => array( 'bk_review_checkbox', '=', 1),
),
array(
'visible' => array( 'bk_review_checkbox', '=', 1),
'type' => 'divider',
),
//Pros & Cons
array(
'name' => esc_html__( 'Pros and Cons', 'ceris' ),
'id' => 'bk_pros_cons',
'type' => 'checkbox',
'desc' => esc_html__( 'Enable Pros and Cons On This Post', 'ceris' ),
'std' => 0,
'visible' => array( 'bk_review_checkbox', '=', 1),
),
array(
'visible' => array( 'bk_pros_cons', '=', 1),
'type' => 'divider',
),
array(
'name' => esc_html__( 'Pros Title', 'ceris' ),
'id' => 'bk_review_pros_title',
'type' => 'textarea',
'cols' => 20,
'rows' => 2,
'visible' => array( 'bk_pros_cons', '=', 1),
),
array(
'name' => esc_html__( 'Pros (Advantages)', 'ceris' ),
'id' => 'bk_review_pros',
'type' => 'textarea',
'cols' => 20,
'clone' => true,
'rows' => 2,
'visible' => array( 'bk_pros_cons', '=', 1),
),
array(
'visible' => array( 'bk_pros_cons', '=', 1),
'type' => 'divider',
),
array(
'name' => esc_html__( 'Cons Title', 'ceris' ),
'id' => 'bk_review_cons_title',
'type' => 'textarea',
'cols' => 20,
'rows' => 2,
'visible' => array( 'bk_pros_cons', '=', 1),
),
array(
'name' => esc_html__( 'Cons (Disadvantages)', 'ceris' ),
'id' => 'bk_review_cons',
'type' => 'textarea',
'cols' => 20,
'clone' => true,
'rows' => 2,
'visible' => array( 'bk_pros_cons', '=', 1),
),
array(
'type' => 'divider',
),
array(
'type' => 'heading',
'name' => esc_html__('Performance and User Review', 'ceris'),
'desc' => esc_html__('This section allow you to have some criterias and allow your reader to share their review', 'ceris'),
),
array(
'name' => esc_html__( 'Performance and User Review Check Box', 'ceris' ),
'id' => 'bk_performance_review_checkbox',
'type' => 'checkbox',
'desc' => esc_html__( 'Enable This Review', 'ceris' ),
'std' => 0,
),
array(
'visible' => array( 'bk_performance_review_checkbox', '=', 1),
'type' => 'divider',
),
array(
'id' => 'bk_performance_review_score_criteria_group',
// Group field
'type' => 'group',
// Clone whole group?
'clone' => true,
'visible' => array( 'bk_performance_review_checkbox', '=', 1),
// Sub-fields
'fields' => array(
array(
'name' => esc_html__( 'Criteria Title', 'ceris' ),
'id' => 'review_criteria_title',
'type' => 'text',
),
array(
'name' => esc_html__( 'Criteria Score', 'ceris' ),
'id' => 'review_criteria_score',
'class' => 'ceris-',
'type' => 'slider',
'js_options' => array(
'min' => 0,
'max' => 10.05,
'step' => .1,
),
),
),
),
array(
'type' => 'divider',
),
array(
'name' => esc_html__( 'Reader Review Form', 'ceris' ),
'id' => 'bk_reader_review_checkbox',
'visible' => array( 'bk_performance_review_checkbox', '=', 1),
'type' => 'checkbox',
'desc' => esc_html__( 'Enable Reader Review', 'ceris' ),
'std' => 0,
),
)
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'bk_child_register_meta_boxes', 999,1 );

Adding Row settings to WPBakery plugin

How do I get the settings to the frontend? I need to add classes to vc_row.
/**
* Ken Burns Effect for Row.
*/
add_action( 'vc_after_init', 'ken_burns_effect_add_option_to_vc_row' );
function ken_burns_effect_add_option_to_vc_row() {
// Ken Burns Effect Attributes
$ken_burns_effect_attributes =
array(
array(
'type' => 'checkbox',
'heading' => __( 'Ken Burns for image background', 'ken_burns_effect' ),
'param_name' => 'enable_ken_burns_effect',
'value' => array(
__( 'Yes', 'ken_burns_effect' ) => 'yes',
),
'description' => 'Check this box if you want to enable ken burns effect for this row.',
),
array(
'type' => 'dropdown',
'heading' => __( 'Direction', 'ken_burns_effect' ),
'param_name' => 'direction_ken_burns_effect',
'value' => array(
'Zoom In' => 'zoom_in',
'Zoom Out' => 'zoom_out',
),
'description' => __( '', 'ken_burns_effect' ),
'dependency' => array(
'element' => 'enable_ken_burns_effect',
'value' => array( 'yes' ),
),
),
array(
'type' => 'textfield',
'heading' => __( 'Transition speed', 'ken_burns_effect' ),
'param_name' => 'transition_speed_ken_burns_effect',
'value' => '',
'description' => __( '', 'ken_burns_effect' ),
'dependency' => array(
'element' => 'enable_ken_burns_effect',
'value' => array( 'yes' ),
),
),
);
vc_add_params( 'vc_row', $ken_burns_effect_attributes);
}
You will have to override the vc_row.php by copying it to your theme or plugin.
You can check their documentation on how to set the override directory: https://kb.wpbakery.com/docs/inner-api/vc_set_shortcodes_templates_dir/
Then you can use your custom params inside vc_row.php using their param_name eg:
$enable_ken_burns_effect;
$direction_ken_burns_effect;
$transition_speed_ken_burns_effect;
Keep in mind that you have to override vc_row_inner.php too if you want to use options there. Same goes for section and columns.

Get data from custom customize field

I've setup new fields below, there's two types for images and text how can I call it now on a php file I'm assuming there's a function for it.
I'm able to access the fields on the theme > customize and add data to it but now I want to paste on a template.
$wp_customize->add_section('travel_video', array(
'priority' => 16,
'capability' => 'edit_theme_options',
'title' => __(' - Featured Videos', 'travel-lite'),
'description' => ''
));
$wp_customize->add_setting('travel[fpvideo]', array(
'default' => __('Title 1', 'travel-lite'),
'capability' => 'edit_theme_options',
'sanitize_callback' => 'esc_textarea',
'type' => 'option'
));
$wp_customize->add_control('travel_fpvideo' , array(
'label' => __('Title 1', 'travel-lite'),
'section' => 'travel_video',
'settings' => 'travel[fpvideo]'
));
Try This code,you can look for reference customizer
function mytheme_customize_register($wp_customize) {
$wp_customize->add_section('travel_video', array(
'priority' => 16,
'capability' => 'edit_theme_options',
'title' => __(' - Featured Videos', 'travel-lite'),
'description' => ''
));
$wp_customize->add_setting('travel[fpvideo]', array(
'default' => __('Title 1', 'travel-lite'),
'capability' => 'edit_theme_options',
'sanitize_callback' => 'esc_textarea',
'type' => 'option'
));
$wp_customize->add_control('travel_fpvideo', array(
'label' => __('Title 1', 'travel-lite'),
'section' => 'travel_video',
'settings' => 'travel[fpvideo]'
));
}
add_action('customize_register', 'mytheme_customize_register');

Categories