Conditional Logic Custom Callback not working for me
- This topic has 4 replies, 2 voices, and was last updated 8 years, 4 months ago by
bdthemes.
-
AuthorPosts
-
June 20, 2017 at 1:00 PM #6107
bdthemes
ParticipantHello,
I used this logic: 'visible' => ['orphan_toolbar_check()', true]
Callback Function is:
function orphan_toolbar_check() {
if ( get_theme_mod('orphan_toolbar') ) {
return true;
} else {
return false;
}
}but it's not working for me, can you help about it?
it's showing this error in console: http://prntscr.com/flv12i (it's showing orphan_toolbar_check is not defined but i already define it)
NOTE: i am using Metabox: 4.10.1 and conditional logic: 1.4.1
June 20, 2017 at 4:25 PM #6109Tan Nguyen
ParticipantDear bdthemes,
Conditional Logic works with Javascript callback only, it doesn't works with PHP, however, with PHP, you can check if meet a condition and then register meta box or field, like so:
if (get_theme_mod('orphan_toolbar')) { $meta_boxes = [ ... ]; }June 21, 2017 at 2:26 AM #6113bdthemes
ParticipantHello Nguyen, Thanks for your reply. You told whole metabox in condition but I want to show/hide one field for depend on one customizer setting. So how can do it?
For example:
I want to show/hide toolbar option depend on this customizer field:
get_theme_mod( 'orphan_toolbar'); // This return true/false
I want visible this metabox field when i get true from get_theme_mod( 'orphan_toolbar'). My field code look like:
array( 'name' => 'Toolbar', 'id' => $prefix . "toolbar", 'type' => 'checkbox', 'desc' => 'Enable or disable the toolbar for this page.', 'tab' => 'layout', 'visible' => [what condition i need to set for it?], ),
June 21, 2017 at 9:08 AM #6117Tan Nguyen
ParticipantDear bdthemes,
Here is an example:
add_filter( 'rwmb_meta_boxes', 'YOURPREFIX_register_meta_boxes' ); function YOURPREFIX_register_meta_boxes( $meta_boxes ) { // Define a meta box $meta_box = array( 'title' => __( 'Media', 'textdomain' ), 'post_types' => 'post', 'fields' => array( array( 'name' => __( 'URL', 'textdomain' ), 'id' => 'url', 'type' => 'text', ), ) ); // Add new field when condition meets if (get_theme_mod( 'orphan_toolbar')) { $meta_box['fields'][] = array( 'name' => 'Toolbar', 'id' => $prefix . "toolbar", 'type' => 'checkbox', 'desc' => 'Enable or disable the toolbar for this page.', 'tab' => 'layout', ), } // Add the meta box to $meta_boxes array to register $meta_boxes[] = $meta_box; }June 22, 2017 at 1:59 AM #6143bdthemes
ParticipantI understand it, Thanks for your help 🙂
-
AuthorPosts
- The topic ‘Conditional Logic Custom Callback not working for me’ is closed to new replies.