Is it possible to include this function
function Get_All_Wordpress_Menus(){
return get_terms( 'nav_menu', array( 'hide_empty' => true ) );
}
into this array
array(
'options' => ADD_FUNCTION_HERE,
);
Is it possible to include this function
function Get_All_Wordpress_Menus(){
return get_terms( 'nav_menu', array( 'hide_empty' => true ) );
}
into this array
array(
'options' => ADD_FUNCTION_HERE,
);
You need this ?
function Get_All_Wordpress_Menus(){
return get_terms( 'nav_menu', array( 'hide_empty' => true ) );
}
$arr = array(
'options' => Get_All_Wordpress_Menus(),
);
If you want to store the function in an array do this:
Example
function foo($text = "Bar")
{
echo $text;
}
// Pass the function to the array. Do not use () here.
$array = array(
'func' => "foo" // Reference to function
);
// And call it.
$array['func'](); // Outputs: "Bar"
$array['func']("Foo Bar"); // Outputs: "Foo Bar"
If you need to pass the return value, it's very simple (assuming previous example):
$array['value'] = foo();
If you need to store the function itself, use anonymous functions
$arr = array(
'options' => function()
{
return get_terms( 'nav_menu', array( 'hide_empty' => true ) );
}
);
You can then call it like
$func = $arr['options'];
$func();
http://php.net/manual/en/functions.anonymous.php
Note that before PHP 5.3 it was not possible. Although there is a workaround that is described in Closure objects within arrays before PHP 5.3
function Get_All_Wordpress_Menus($call){
$call = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
return $call;
}
$array = array(
'options' => $call,
);
OR
$array = array(
'options' => Get_All_Wordpress_Menus($call),
);