Hi - I am working through setting up some functions and the following very basic example explains where I am currently at - the function would be designed to have an array ($args) passed to it - this is merged with the defaults that I have filtering and translation setup on:
PHP Code:
function my_function($args) {
// Setup default with filtering and translation
$defaults = array (
'my_text' => apply_filters( 'my_text_filter', __('My text default string here ', 'my_plugin') )
);
$args = wp_parse_args( $args, $defaults );
extract( $args, EXTR_SKIP );
// DATA VALIDATION CODE FOR $my_text HERE
// Final cleanup ready for use
$my_text_clean = esc_attr( wp_kses_data($my_text, '') );
return $my_text_clean;
}
I'm preparing it for output at the end with esc_attr() - would you suggest that this is best done elsewhere or within the function? I could always build 'output_style' into the $args for this - but that's not too relevant at the moment. I'm just looking for the neatest (and I guess safest!) way to add the ability for filtering and translation in a function.
Any thoughts on this would be much appreciated - I'm not exactly a super-duper code warrior - just trying to do the right thing so users get the most out of the code I'm creating. Is there a better/more flexible way to achieve this?