Skip to content

Filters

rogerlos edited this page Jun 16, 2017 · 20 revisions

The following filters are accessible via add_filter(). Included are sample closures, with comments

Within Flexwalker Class

Configuration and HTML construction outside of the actual WordPress Menu.

Menu Arguments: Append Numeric?

When merging $args and $this->cfg, append (true) or overwrite (false) array values which have a numeric key?

add_filter( 'flexwalker_menu_numeric', function( $bool ) {

    // always append
    return TRUE;
}, 10, 1 );

Menu Arguments: Values

The merged array of arguments being used by Flexwalker.

add_filter( 'flexwalker_menu_args', function( $array ) {

    // change walker container_id argument
    $array['walker']['container_id'] = 'mynewid';

    return $array;
}, 10, 1 );

Menu Structure: Template

The template being used by Flexwalker. Note, this needs to be in the 'template' format, see JSON: templates. If it's empty, Flexwalker will return nothing.

add_filter( 'flexwalker_menu_template', function( $array ) {

    // change depth
    $array['depth'] = 1;

    return $array;
}, 10, 1 );

Menu ID

Flexwalker by default generates a random ID to assign to the menu.

add_filter( 'flexwalker_menu_id', function( $string ) {

    // change to your own value.
    return 'myniftyid';
}, 10, 1 );

HTML: Structure Tags

This is structure of the HTML returned, see JSON: templates for more information. There should be a special walker item in this array if you are actually calling a menu.

add_filter( 'flexwalker_navbar_tags', function( $tags_array, $template_id ) {

    // be careful here, see JSON: templates

    return $tags_array;
}, 10, 2 );

HTML Build: Opening Tag Array

$key is the tag's key within $this->cfg['tags'].

add_filter( 'flexwalker_navbar_open_tag', function( $array, $key, $template_id ) {

    // $array is a tag array as seen in JSON: tags

    return $array;
}, 10, 3 );

Javascript Localization

Filter the array of data which is being made available to flexwalker.js. Note that arbitrarily changing the structure or keys will probably break things.

/* 
 * $array contains the contents of $this->cfg['display'] as modified by the 
 * passed arguments when flexwalker( $args ). $this->cfg['display'] is initially
 * the contents of display.json
 */
add_filter( 'flexwalker_localize', function( $array ) {

    // turn off resize hiding
    $array['resizehide']['use'] = false;

    return $array;
}, 10, 1 );

Clone this wiki locally