parse_menu_hook (function)

Last updated: Mon, Apr 17, 2023 1:26 pm
Return to Knowledgebase

Purpose

Used to replace strings in a given input string using an array of replacements.

Location

users/helpers/menus.php

Parameters

# Parameter Data Type Required Description
1 $find string, array Yes An array of strings to be replaced.
2 $replace string, array Yes An array of replacement strings for the $find strings. If a replacement string is not specified for a corresponding $find string, an empty string will be used as the replacement.
3 $string string Yes The input string that will be searched for the $find strings.

Returns

Data Type Description of Returned Data
string Returns the input string with any instances of the $find strings replaced with their corresponding $replace strings.

Further Documentation:

Here is an example of how to use the parse_menu_hook function:


$menu_item = "{{label}}";
$replacements = array(
"{{url}}" => "https://example.com",
"{{label}}" => "Home"
);
$updated_menu_item = parse_menu_hook(array_keys($replacements), array_values($replacements), $menu_item);
echo $updated_menu_item;



In this example, the $menu_item variable contains an HTML link with two placeholders ({{url}} and {{label}}). The $replacements array contains the values that will replace these placeholders. The array_keys function is used to extract the keys of the $replacements array as the $find parameter for the parse_menu_hook function, and the array_values function is used to extract the values of the $replacements array as the $replace parameter. The parse_menu_hook function is called with these parameters and the resulting string with the replaced values is stored in the $updated_menu_item variable. Finally, the $updated_menu_item variable is echoed to output the updated HTML link.