Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save badabingbreda/8bc2aeaa54d18fdd58871bd860bf0b2e to your computer and use it in GitHub Desktop.
Save badabingbreda/8bc2aeaa54d18fdd58871bd860bf0b2e to your computer and use it in GitHub Desktop.
Toolbox Action - toolbox_add_conditional_options
<?php
add_action( 'toolbox_add_conditional_options' , 'add_some_new_conditional_feature', 10, 1 );
function add_some_new_conditional_feature() {
toolboxExtender::add_conditional_option(
// filter name
'conditional_filter_check_parameter',
// option key and title
array('key'=> 'check_parameter' , 'title' => __('Check URL Parameter', 'textdomain') ),
// fields that are part of this options settings.
// No toggling of subfields or forms
array(
'query_parameter' => array(
'type' => 'text',
'label' => __( 'query parameter to check for', 'textdomain' ),
),
'query_value' => array(
'type' => 'text',
'label' => __( 'if equal to', 'textdomain' ),
),
)
);
add_filter( 'conditional_filter_check_parameter' , 'check_query_parameter' , 10, 3 );
function check_query_parameter ( $is_visible, $param , $node ) {
if ( !isset( $_GET[$param['query_parameter']]) || $_GET[$param['query_parameter']] !== $param['query_value'] ) return false;
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment