Purpose

Make template values URL-safe by transforming specific keys’ values using the urlencode function.

Usage

add_filter('wr_template_replace_value', "make_filename_urlsafe", 10, 2);

Parameters

  • $value (mixed): The current value of the template key.
  • $key (string): The key associated with the value.

Use Case

This functionality is useful when:

  • You need to ensure that certain values (e.g., file names) are safe for use in URLs.
  • You want to standardize URL-safe formatting for specific template keys.

Implementation Example

add_filter( "wr_template_replace_value", "make_filename_urlsafe", 10, 2 );
 
public function make_filename_urlsafe( $value, $key ) {
	if ( $key == "file_name" ) {
		$value = urlencode( $value );
	}
	return $value;
}