Created
March 26, 2017 07:32
-
-
Save Binternet/bdf1e064fcb3cd46654f59a1d871e120 to your computer and use it in GitHub Desktop.
where-did-they-go-from-here Referer filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Enqueues the scripts needed by WDTGFH. | |
* | |
* @since 1.7 | |
* @return void | |
*/ | |
function wherego_enqueue_scripts() { | |
global $post; | |
if ( is_singular() ) { | |
wp_enqueue_script( 'wherego_tracker', plugins_url( 'includes/js/wherego_tracker.js', WHEREGO_PLUGIN_FILE ), array( 'jquery' ) ); | |
wp_localize_script( 'wherego_tracker', 'ajax_wherego_tracker', array( | |
'ajax_url' => admin_url( 'admin-ajax.php' ), | |
'wherego_nonce' => wp_create_nonce( 'wherego-tracker-nonce' ), | |
'wherego_id' => $post->ID, | |
'wherego_sitevar' => wherego_get_referer(), | |
'wherego_rnd' => wp_rand( 1, time() ), | |
) | |
); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'wherego_enqueue_scripts' ); | |
/** | |
* Referer filter | |
* This allows us to manipulate and trick the plugin for custom tracking | |
* | |
* @return string | |
*/ | |
function wherego_get_referer() { | |
$referer = isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : ''; | |
return apply_filters( 'wherego_get_referer', $referer ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment