__construct($meta, $control_in_head); } function __construct($meta = 'gwo4wp', $control_in_head = true) { $this->meta = $meta; $this->control_in_head = $control_in_head; add_action('plugins_loaded', array(&$this, 'action_plugins_loaded')); } function action_plugins_loaded() { if (is_admin()) { require_once(ABSPATH . 'wp-admin/includes/template.php'); // Needed for add_meta_box() add_meta_box('gwo_section', 'Google Website Optimizer', array(&$this, 'meta_box_post'), 'post', 'normal', 'high'); add_meta_box('gwo_section', 'Google Website Optimizer', array(&$this, 'meta_box_post'), 'page', 'normal', 'high'); add_action('save_post', array(&$this, 'action_save_post'), 1, 2); } else { add_action('template_redirect', array(&$this, 'action_template_redirect')); } } function action_wp_head() { echo(''); if ($this->control_in_head) { echo($this->control_script); } } function action_template_redirect() { if (is_single() || is_page()) { global $post; $options = get_post_meta($post->ID, $this->meta, true); if (isset($options['enabled']) && $options['enabled']) { add_action('wp_head', array(&$this, 'action_wp_head')); $this->control_script = isset($options['control_script']) ? trim($options['control_script']) : ''; $this->tracking_script = isset($options['tracking_script']) ? trim($options['tracking_script']) : ''; $this->conversion_script = isset($options['conversion_script']) ? trim($options['conversion_script']) : ''; ob_start(array(&$this, 'ob_start_callback')); } } } function ob_start_callback($content) { if (!$this->control_in_head) { $html = $this->control_script; if ($html != '') { $content = preg_replace('#]*>#si', "$0\r\n{$html}\r\n", $content); } } $html = trim($this->tracking_script . "\r\n" . $this->conversion_script); if ($html != '') { $content = preg_replace('#]*>#si', "\r\n{$html}\r\n$0", $content); } return $content; } function action_save_post($post_id, $post) { if ($post->post_type != 'revision') { $options = array(); $options['enabled'] = isset($_POST['enable_gwo']) && ($_POST['enable_gwo'] == '1'); $options['control_script'] = isset($_POST['control_script']) ? trim($_POST['control_script']) : ''; $options['tracking_script'] = isset($_POST['tracking_script']) ? trim($_POST['tracking_script']) : ''; $options['conversion_script'] = isset($_POST['conversion_script']) ? trim($_POST['conversion_script']) : ''; if (!update_post_meta($post->ID, $this->meta, $options)) { add_post_meta($post->ID, $this->meta, $options); } } } function meta_box_post() { global $post; $options = get_post_meta($post->ID, $this->meta, true); if (is_array($options)) { $options['enabled'] = isset($options['enabled']) ? (bool)$options['enabled'] : false; $options['control_script'] = isset($options['control_script']) ? trim($options['control_script']) : ''; $options['tracking_script'] = isset($options['tracking_script']) ? trim($options['tracking_script']) : ''; $options['conversion_script'] = isset($options['conversion_script']) ? trim($options['conversion_script']) : ''; } else { $options['enabled'] = false; $options['control_script'] = ''; $options['tracking_script'] = ''; $options['conversion_script'] = ''; } $url = get_bloginfo('wpurl') . '/' . PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)); ?>
To use this plugin you must register a Google Website Optimizer account. It's free.
 
/>
 
 

Insert here the Control Script provided by the Google Website Optimizer.
You must fill this field only if this page/post is your Original page.
 
 

Insert here the Tracking Script provided by the Google Website Optimizer.
You must fill this field only if this page/post is your Original page or a Variation page.
 
 

Insert here the Conversion Script provided by the Google Website Optimizer.
You must fill this field only if this page/post is your Conversion page.