i am building a plugin and i want to add some settings which rely on checkboxes. if the user checks the checkbox how to know. i know how to get data from checkbox in php but got stuck in wordpress. Because we have no option to add name attribute to the checkbox. for example, i am adding a checkbox in customizer.
$wp_customize->add_setting('ion', array(
'sanitize_callback' => 'ion_checkbox'
));
$wp_customize->add_control(new WP_Customize_Control($wp_customize, 'ion', array(
'label' => 'Check',
'type' => 'checkbox',
'section' => 'search_submit_section',
'settings' => 'ion'
)));
As we see there is no option to add name attribute how we will know whether user has checked the checkbox or not. I hope you understand my question.
Thanks in advance
with ($wp_customize, 'ion', array.... the ID is ion you can get the value with
$ion_checkbox_checked = get_theme_mod('ion') ? true : false;
if the checkbox checked get_theme_mod('ion') will return 1 else 0
Related
Wordpress admin customizer control is incomplete. How can I fix it?
My Code:
$wp_customize->add_setting('swag_header_media');
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'swag_header_media', array(
'label' => 'Current Image Selection',
'section' => 'swag_header_media_section',
'active_callback' => 'header_show_image_selection_settings_callback',
'settings' => 'swag_header_media'
)));
The results are incomplete. I can select an image from the and the image show up in the frontend of the theme. However, the image selected does not show that it is being used in the control.
In other words(see screenshot), you can see the background image being used(phone), but it doesn't show that it being used in the admin customizer control. Its says "Current Image Selection", but it's empty with no buttons below it to change or remove it.
When you inspect the page, is there any errors?
It is a bit hard to figure out with so little data.
Try this 'settings' => 'themename_theme_options[swag_header_media]',
Try:
$wp_customize->add_setting('themename_theme_mods[swag_header_media]',array(
//'default' => 'image.jpg',
//'capability' => 'edit_theme_options',
//'type' => 'option'
));
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'swag_header_media', array(
'label' => 'Current Image Selection',
'section' => 'swag_header_media_section',
'active_callback' => 'header_show_image_selection_settings_callback',
'settings' => 'themename_theme_mods[swag_header_media]'
)));
if that doesnt work,I suggest to change swag_header_media to other keyname. I suspect that key name might be used by other control/funtion too. So, try to add any 1 letter to that keyname, and see the result. Also, if you have any caching on site, turn it off.
also, the problem could be with callback,
I want to hide admin side my custom type Add New button. Review this screen shot -> https://s.nimbus.everhelper.me/share/1406976/p6f5u0nlvs5xff3sr85h
So any one know solutions then please update me.
Thanks.
you can use meta capability create_posts that is not documented but is used by WordPress to check before inserting the various 'Add New' buttons and links. In your custom post type declaration, add capabilities (not to be confused with cap) and then set it to false as below.
register_post_type( 'custom_post_type_name', array(
'capability_type' => 'post',
'capabilities' => array(
'create_posts' => false, // Removes support for the "Add New" function ( use 'do_not_allow' instead of false for multisite set ups )
),
'map_meta_cap' => true, // Set to `false`, if users are not allowed to edit/delete existing posts
));
Where custom_post_type_name you can put your custom post type name, which you are creating.
I've downloaded the Redux Framework (using generator). I want some fields to be displayed if a checkbox field is checked (more related fields below checkbox).
I searched online and found some Redux code having checkbox_hide_below field which is not present in the current Redux Framework.
Will I have to do it all by myself or Redux framework provides some option to show/hide fields?
Lead dev of Redux here.
You'd have to do it yourself, however it's really pretty easy.
First, you'd do a get_option to your opt_name before you run your config. Then on the fields you want to make hidden you'd do something like this:
$options = get_options('OPT_NAME');
$field = array(
'id' => 'textarea_id',
'type' => 'textarea',
'hidden' => ( $options['test_value'] == 1 ) ? true : false,
'title' => __( 'Test Hidden Field', 'redux-framework-demo' ),
'desc' => __( 'This field will be set to be hidden if text_value is 1.', 'redux-framework-demo' ),
);
It's pretty strait forward. I hope that helps! You can also apply the hidden argument to sections as well. ;)
I want to add several image upload fields to my theme options by using the WP Customization API.
For each of these upload fields I want to rename the uploaded file to a fixed name.
So for example, I want to add a hero_image field, and it should always be stored as hero.jpg.
I added a setting called hero_image,
$wp_customize->add_setting( 'hero_image' , array(
'default' => '',
) );
This is the related control
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
'hero_image_control',
array(
'label' => 'Site hero',
'section' => 'context_settings',
'settings' => 'hero_image',
'context' => 'your_setting_context'
)
)
);
I know I can add a sanitize callback, but this won't rename the uploaded file.
If anyone knows how to add a preupload filter for a specific field, it would make my day :D
http://www.photouploads.com/images/customfiel.jpg
i have configure a taxonomy as field of a content type, but i want to replace the checkbox label(work with iphone) to an image which is a image field of that taxonomy(see the photo).
At now i only know to alter node.pages.inc at row 290 by add the code:
$form['product_label'] = array(
'#type' => 'checkboxes',
'#title' => 'Checkboxes Title',
'#title_display' => 'before',
'#default_value' => array(0,2),
'#options' => array(
0 => 'option one',
1 => 'option two',
2 => 'option three',
),
'#theme' => 'testmodule_checkboxes',
);
the product_label is the checkbox name, the above code is to override the current checkbox field. But i think this a not a best way to do..
anyone can provide direction to me? what module or coding can do it?
You shouldn't hack core (except in very few edge cases if you really know what you're doing).
The best place to do this is in your theme. In template.php, you need to use the hook, hook_form_alter() to alter that specific form. You can find out more about the FAPI (form API) here and here.
There's a few ways to alter the form to get the result you want. The easiest way would be to add a unique class for each icon to each form item's attributes array. You can then use CSS to replace the text with the icon (this makes it more accessible as screen readers will still be able to read the text).