Challenge - 5 Problems
Filter Hook Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this filter hook modification?
Consider the following WordPress filter hook code. What will be the final output of
apply_filters('greet', 'Hello')?Wordpress
<?php add_filter('greet', function($text) { return $text . ', friend!'; }); add_filter('greet', function($text) { return strtoupper($text); }); echo apply_filters('greet', 'Hello'); ?>
Attempts:
2 left
💡 Hint
Remember that filters run in the order they are added, and each filter receives the output of the previous one.
✗ Incorrect
The first filter appends ', friend!' to 'Hello', making 'Hello, friend!'. The second filter converts the entire string to uppercase, resulting in 'HELLO, FRIEND!'.
📝 Syntax
intermediate1:30remaining
Which option causes a syntax error in adding a filter?
Which of the following filter hook additions will cause a PHP syntax error?
Attempts:
2 left
💡 Hint
Check for missing punctuation or braces in the function syntax.
✗ Incorrect
Option C is missing the closing semicolon and closing brace for the anonymous function, causing a syntax error.
❓ state_output
advanced2:00remaining
What is the value of $content after applying these filters?
Given the following code, what is the value of
$content after apply_filters('content_filter', $content)?Wordpress
<?php $content = 'Start'; add_filter('content_filter', function($text) { return $text . ' + First'; }); add_filter('content_filter', function($text) { return $text . ' + Second'; }, 5); $content = apply_filters('content_filter', $content); ?>
Attempts:
2 left
💡 Hint
Lower priority numbers run earlier in WordPress filters.
✗ Incorrect
The filter with priority 5 runs before the default priority 10. So ' + Second' is added first, then ' + First'.
🔧 Debug
advanced1:30remaining
Which option causes a runtime error when applying this filter?
Given this filter hook, which option will cause a runtime error when
apply_filters('number_filter', 10) is called?Wordpress
<?php add_filter('number_filter', function($num) { return $num * 2; });
Attempts:
2 left
💡 Hint
Consider the type of the input and what operations are valid on it.
✗ Incorrect
Option D tries to access a property on an integer, causing a fatal error.
🧠 Conceptual
expert2:30remaining
Which option best describes how filter hooks modify data in WordPress?
Select the option that correctly explains how filter hooks work in WordPress.
Attempts:
2 left
💡 Hint
Think about how data flows through filters and how the output changes.
✗ Incorrect
Filters pass data through multiple functions, each can modify and return the data, allowing flexible changes without altering core code.