Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

josh.shand on "wp_referer_field function mod"

$
0
0

Hi guys,

I'm implementing a blog under /blog which isn't actually in a subfolder and not using MS.

We actually have the majority of this working so don't worry about that too much. My only requirement for any mods is that I don't modify any core files so upgrades are still supported.

I need to be able to "fix" the hidden _wp_http_referer input so that it contains /blog for admin pages otherwise I get thrown to the wrong page when I save settings with a POST. This is in wp-includes/functions.php (line 1263), like so:

$referer_field = '<input type="hidden" name="_wp_http_referer" value="/blog'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';

Editing the core functions.php works perfectly but I want to achieve this by some other method. As it's not a pluggable function is is possible to use an add_action somewhere to "re-set" the variable before the page is rendered?

Something along the lines of this (tried in a plugin and doesn't work)?

function custom_wp_referer_field( $echo = true ) {
	$referer_field = '<input type="hidden" name="_wp_http_referer" value="/blog'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';

	if ( $echo )
		echo $referer_field;
	return $referer_field;
}
add_action('admin_init','custom_wp_referer_field');

Hopefully this makes some sense anyway - let me know what the gurus come up with!

Cheers


Viewing all articles
Browse latest Browse all 8245

Trending Articles