Skip to content

Instantly share code, notes, and snippets.

@tbartels
Created November 21, 2013 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tbartels/7580798 to your computer and use it in GitHub Desktop.
Save tbartels/7580798 to your computer and use it in GitHub Desktop.
Adjust google-analytics-for-wordpress by Yoast to clean up magic quotes and allow for a custom script that correctly writes Javascript so alternate tracking codes will validate.
<?php
/**
Plugin Name: Google Analytics for Wordpress Slashes Fix
Description: Strip slashes on the GAforWP plugin by Yoast to correctly avoid excess/infinite magic quotes.
Version: 0.1.0
Author: Thomas Bartels &lt;<a href="mailto:tbartels@gmail.com">tbartels@gmail.com</a>&gt;
This plugin fixes the options for Yoast's 'google-analytics-for-wordpress' plugin
allowing for more complex content to be used in the form fields. Specifically it
will now be possible to put Javascript in the `gajsurl` field in order to use the
Demographics tracking code from Google Analytics. Once this plugin is installed
and enabled select the 'Host ga.js locally' option and enter (with quotes!!):
'+('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js
as the URL for the ga.js file.
*/
if ( class_exists( "GA_Admin" ) ) {
global $ga_admin;
function fix_ga4wp_slashes( $new, $old="" ) {
return stripslashes_deep( $new );
}
add_filter( "pre_update_option_{$ga_admin->optionname}", "fix_ga4wp_slashes", 10, 2 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment