Skip to content

Instantly share code, notes, and snippets.

@Binternet
Created March 26, 2017 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Binternet/bdf1e064fcb3cd46654f59a1d871e120 to your computer and use it in GitHub Desktop.
Save Binternet/bdf1e064fcb3cd46654f59a1d871e120 to your computer and use it in GitHub Desktop.
where-did-they-go-from-here Referer filter
/**
* 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