PHP: unstring without eval (using Wordpress nav walker in shortcode)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



PHP: unstring without eval (using Wordpress nav walker in shortcode)



I'm playing with the code for the Wordpress extension "Menu Shortcode" to try to get its walker function working. Here's the shortcode as it appears in a page:


[listmenu menu=TOC]



(This works whether or not the value is in quotes)



And the plugin code:


<?php

function list_menu($atts, $content = null)
extract(shortcode_atts(array(
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'depth' => 0,
'walker' => '',
'theme_location' => ''),
$atts));

return wp_nav_menu( array(
'menu' => $menu,
'container' => $container,
'container_class' => $container_class,
'container_id' => $container_id,
'menu_class' => $menu_class,
'menu_id' => $menu_id,
'echo' => false,
'fallback_cb' => $fallback_cb,
'before' => $before,
'after' => $after,
'link_before' => $link_before,
'link_after' => $link_after,
'depth' => $depth,
'walker' => $walker,
'theme_location' => $theme_location));


//Create the shortcode
add_shortcode("listmenu", "list_menu");
add_filter ('widget_text', 'do_shortcode');



Some of these attributes work just fine (ie. I can set a depth, a link_before, etc. in the shortcode) but some don't - container doesn't seem to work and, relevant for what I'm working on, walker doesn't work. Am I right in thinking that the code is probably taking in "new Extended_Walker()" as a string and thus failing to initialize it? I experimented with using eval(), but it didn't seem to work, besides being dangerous! Is there a way I can allow the choice of walker to be set in the shortcode?



Thanks!









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard