|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Gravity Wiz // Gravity Forms // Split Testing for Gravity Forms |
4 | | - * |
5 | | - * Allows you to test the effectiveness of two or more Gravity Forms by using a single shortcode (or function call) to |
6 | | - * randomly alternating which form is displayed. Effectiveness can be measured by the "Conversion" column available |
7 | | - * by default on the Gravity Forms' "Forms" list view. |
8 | | - * |
9 | | - * Based on https://gist.github.com/fatmedia/8289103 by @realFATmedia via @mattreport |
10 | | - * |
11 | | - * @version 1.0 |
12 | | - * @author David Smith <[email protected]> |
13 | | - * @license GPL-2.0+ |
14 | | - * @link http://gravitywiz.com/simple-split-testing-gravity-forms/ |
15 | | - * @copyright 2013 Gravity Wiz |
| 3 | + * This snippet is now available as a free plugin with Spellbook. ✨ |
| 4 | + * Instructions for installing this plugin can be found here: |
| 5 | + * https://gravitywiz.com/path-to-free-plugin-article/ |
16 | 6 | */ |
17 | | -class GW_Split_Testing { |
18 | | - |
19 | | - protected static $instance = null; |
20 | | - |
21 | | - public static function get_instance() { |
22 | | - |
23 | | - if ( null == self::$instance ) { |
24 | | - self::$instance = new self; |
25 | | - } |
26 | | - |
27 | | - return self::$instance; |
28 | | - } |
29 | | - |
30 | | - private function __construct() { |
31 | | - |
32 | | - add_filter( 'gform_shortcode_split_test', array( $this, 'do_split_test_shortcode' ), 10, 2 ); |
33 | | - |
34 | | - } |
35 | | - |
36 | | - public function do_split_test_shortcode( $output, $atts ) { |
37 | | - |
38 | | - // get our "random" form ID from the provided form IDs |
39 | | - $form_ids = array_map( 'trim', explode( ',', $atts['ids'] ) ); |
40 | | - |
41 | | - return $this->get_split_test_form( $form_ids, $atts ); |
42 | | - } |
43 | | - |
44 | | - public function get_split_test_form( $form_ids = array(), $atts = array() ) { |
45 | | - |
46 | | - if ( empty( $form_ids ) ) { |
47 | | - return; |
48 | | - } |
49 | | - |
50 | | - if ( rgpost( 'gform_submit' ) && in_array( rgpost( 'gform_submit' ), $form_ids ) ) { |
51 | | - $form_id = rgpost( 'gform_submit' ); |
52 | | - } else { |
53 | | - $index = mt_rand( 0, count( $form_ids ) - 1 ); |
54 | | - $form_id = $form_ids[ $index ]; |
55 | | - } |
56 | | - |
57 | | - // modify attributes to create form-generating shortcode |
58 | | - $atts['action'] = 'form'; |
59 | | - $atts['id'] = $form_id; |
60 | | - |
61 | | - // generate [gravityform] form shortcode |
62 | | - $shortcode_bits = array(); |
63 | | - foreach ( $atts as $key => $value ) { |
64 | | - |
65 | | - if ( is_array( $value ) ) { |
66 | | - $value = implode( ',', $value ); |
67 | | - } |
68 | | - |
69 | | - if ( $value === true ) { |
70 | | - $value = 'true'; |
71 | | - } |
72 | | - |
73 | | - if ( $value === false ) { |
74 | | - $value = 'false'; |
75 | | - } |
76 | | - |
77 | | - $shortcode_bits[] = "{$key}=\"$value\""; |
78 | | - } |
79 | | - $shortcode = '[gravityform ' . implode( ' ', $shortcode_bits ) . ' /]'; |
80 | | - |
81 | | - // get the form markup by processing the generated shortcode |
82 | | - $form_markup = do_shortcode( $shortcode ); |
83 | | - |
84 | | - return $form_markup; |
85 | | - } |
86 | | - |
87 | | -} |
88 | | - |
89 | | -function gw_split_testing() { |
90 | | - return GW_Split_Testing::get_instance(); |
91 | | -} |
92 | | - |
93 | | -gw_split_testing(); |
0 commit comments