0

I'd like to override the core Wordpress function wp_referer_field to change the value of $referer_field variable inside of it. I've found that wp_referer_field is not pluggable and that I need to use some other technics for that. Adding some filters or actions. I was trying to use these code:

add_filter( 'wp_referer_field' , 'wp_referer_field_cyrillic' );
function wp_referer_field_cyrillic( $echo = true ) {
   $referer_field = '<input type="hidden" name="_my_wp_http_referer" value="'.urldecode(esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) )) . '" />';
   if ( $echo )
     echo $referer_field;
   return $referer_field;
}

But it doesn't work. It seems that I did something wrong.

2 Answers 2

2

wp_referer_field is a function. You cannot treat a function like a hook. That isn't how hooks work. That is, you can't hook into a function name. Hooks are intentionally created. (And there are no hooks built into that function)

Secondly, you can't override a function at all, as a rule. Some few functions in WordPress are wrapped in an if(function_exists('..')) conditional. Those are the exceptions. Those can be replaced by creating a new function of the same name, but not by "hooking" into them.

There may be another way to do what you are trying to do if you were to explain the problem in more detail.

See:

1

In addition, the referer value is a security field. If you change it arbitrarily, you'll very likely break your site completely, since it's checked on form submissions and the like.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.