Here's my apply_filters function to return select box options:
function my_shortcode_filters(){
$handle = ''; $value = apply_filters('my_add_shortcode', $handle);
if($value) $handle = "<option value='$value'>$value</option>";
return $handle;
}
Here's the html where I call the function:
<select id="my-selectbox">
<?php echo my_shortcode_filters(); ?>
<option value="">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
And here are the add_filter functions I'm testing with:
add_filter('my_add_shortcode', 'yourprefix_new_sc_handle', 10);
function yourprefix_new_sc_handle(){
return 'myhandle';
}
add_filter('my_add_shortcode', 'yourprefix_new_sc_handle2', 11);
function yourprefix_new_sc_handle2(){
return 'myhandle2';
}
But only the second add_filter function is added to the dropdown menu. If I remove the second function, the first one is added. But when I add the second function, it overwrites the first add_filter. What am I missing here?
Filters are designed to filter content, not just return a value.
IE, you start with a variable being a value of something, then the filters manipulate that value until all filters have been applied and you end up with the final value.
EG:
add_filter( 'my_x', 'test_one' );
function test_one( $var ) {
return $var . 'y';
}
$var = 'x';
echo apply_filters( 'my_x', $var );
Result: xy
as it takes x then appends y to it.
Your above code is doing a return, not doing any actual filtering - thus you're having the error where the last function to run is the result you see.
What I think you're trying to do (and I could be wrong) is using actions, not filters.
Look into add_action()
and do_action()
and see if that helps.