Using h5p_alter_filtered_parameters to modify a Text value on the Interactive Video
Hello, I am hoping someone can help me find a shorter/quicker way to achieve the following;
I have an interactive video and in it I have a Text element, which says "Hello {name}". I will be passing the {name} parameter via an encrypted Query Variable, I have tested that and it works fine using encode/decode within PHP.
It took me a while, but I finally found the right number of internal loops to go through the h5p_alter_filtered_parameters hook and replace it - I have hard-coded it just for testing purposes. I also added the counters for my own benefit, so when testing I can see the structure being shown as the code loops through, which was very helpful but will not be used in the final code, and I have removed all the "echo" statements for ease of reading..
Rather than loop through each item in the Semantic format, is there a way to call exactly the array value I need to update, so if effect search for the phrase "{name}" and replace it, without all the loops below?
The loops below work, they are just not efficient.
The code I have used is as follows;
function h5pmods_alter_parameters($semantics, $name, $majorVersion, $minorVersion) { // Ok, here we go if ($name === 'H5P.InteractiveVideo') { $group_count = 0; $field_count = 0; $item_count = 0; $value_count = 0; $nano_count = 0; foreach($semantics as $semantic_field) { $group_count++; $field_count = 0; foreach($semantic_field as $group_items) { $field_count++; $item_count = 0; foreach($group_items as $individual_items) { $item_count++; $value_count = 0; foreach($individual_items as $value_items) { $value_count++; $nano_count = 0; foreach($value_items as $nano_items) { $nano_count++; $micro_count = 0; foreach($nano_items as $micro_items) { $micro_count++; $mini_count = 0; foreach($micro_items as $mini_items) { $mini_count++; $mini_items = str_replace("{name}", "Simon", $mini_items); $micro_items->text = $mini_items; } } } } } } } } } add_action('h5p_alter_filtered_parameters', 'h5pmods_alter_parameters', 10, 4);
otacke
Thu, 06/26/2025 - 18:42
Permalink
You might want to try one of
You might want to try one of the utility functions outlined at https://github.com/h5p/h5pmods-wordpress-plugin/blob/master/h5pmods.php#...