Usage Examples for Collapsible Widget Area Filters
<?php | |
/** | |
* Example usage of the collapsible-widget-ui-theme filter | |
* We set the priority to 10, and tell WordPress that the callback function should receive 2 arguments | |
* @see http://codex.wordpress.org/Function_Reference/add_filter | |
*/ | |
add_filter( 'collapsible-widget-ui-theme', 'my_theme_cwa_ui_theme', 10, 2 ); | |
function my_theme_cwa_ui_theme( $theme, $opt=null ) { | |
/** | |
* Set a custom jQueryUI theme specifically for use with our WordPress theme | |
* In this instance, the file that contains our custom jQueryUI theme is located at | |
* /js/jquery-ui-custom.css within our active theme's directory. | |
* If you are using a child theme, and the jQueryUI theme is part of the parent theme, | |
* then you should use get_template_directory_uri() instead of get_stylesheet_directory_uri() | |
* @see http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri | |
* @see http://codex.wordpress.org/Function_Reference/get_template_directory_uri | |
*/ | |
return get_stylesheet_directory_uri() . '/js/jquery-ui-custom.css'; | |
} | |
/** | |
* Example usage of the collapsible-widget-area-args filter | |
* This filter allows you to modify the arguments that are sent to the register_sidebar() function | |
* In this example, we change the title wrapper from an <h2> to an <h4>, and add the "widget-title" | |
* class to it, as you might see in many Genesis-based themes | |
* @see http://codex.wordpress.org/Function_Reference/register_sidebar | |
*/ | |
add_filter( 'collapsible-widget-area-args', 'my_theme_cwa_args' ); | |
function my_theme_cwa_args( $args=array() ) { | |
$args['before_title'] = '<h4 class="widgettitle widget-title">'; | |
$args['after_title'] = '</h4>'; | |
return $args; | |
} | |
/** | |
* Example usage of the collapsible-widget-theme-list filter | |
* This filter allows you to remove unwanted jQueryUI themes or add new | |
* jQueryUI themes to the list of available options | |
* In this example, we will remove the Lightness & Darkness themes, and | |
* add a custom theme of our own. | |
*/ | |
add_filter( 'collapsible-widget-theme-list', 'my_theme_jqueryui_theme_list' ); | |
my_theme_jqueryui_theme_list( $themes=array() ) { | |
unset( $themes['ui-lightness'], $themes['ui-darkness'] ); | |
/** | |
* Because this theme is not hosted on Google's CDN, we need to | |
* provide the full URI to the style sheet | |
*/ | |
$themes['my-theme'] = get_stylesheet_directory_uri() . '/js/jquery-ui-custom.css'; | |
} | |
/** | |
* Example usage of the collapsible-widget-defaults filter | |
* Sets the heightStyle argument as a default value for all collapsible widget areas; | |
* this allows that setting to still be overridden on individual areas by using | |
* the collapsible-widget-javascript-arguments filter in conjunction with this | |
* @see http://api.jqueryui.com/accordion/ for all of the options for the accordion | |
* @see http://api.jqueryui.com/tabs/ for all of the options for the tabbed widget | |
*/ | |
add_filter( 'collapsible-widget-defaults', 'my_theme_cwa_defaults' ); | |
function my_theme_cwa_defaults( $defaults=array() ) { | |
$defaults['heightStyle'] = 'content'; | |
/* Be certain to return the modified array, otherwise nothing will change */ | |
return $defaults; | |
} | |
/** | |
* Example usage of the collapsible-widget-javascript-arguments filter | |
* *Important:* This filter is only available in v0.5.1 and beyond of this plugin | |
* Sets the heightStyle argument for all accordion widget areas | |
* @see http://api.jqueryui.com/accordion/#option-heightStyle | |
* @since 0.5.1 | |
*/ | |
add_filter( 'collapsible-widget-javascript-arguments', 'my_theme_modify_cwa_js_args' ); | |
function my_theme_modify_cwa_js_args( $args = array() ) { | |
/** | |
* Loop through all of the existing Collapsible Widget Areas | |
*/ | |
foreach ( $args as $k=>$a ) { | |
/** | |
* Check to see if this is an 'accordion' area or a 'tabbed' area | |
*/ | |
if ( 'accordion' == $a['type'] ) { | |
/** | |
* Set the appropriate jQueryUI accordion argument to the desired value | |
*/ | |
$args[$k]['heightStyle'] = 'content'; | |
} | |
} | |
/** | |
* Be certain to return the modified array, otherwise nothing will happen | |
*/ | |
return $args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment