| 1 |
<?php |
| 2 |
/* Begin Add Card in Admin Panel */ |
| 3 |
add_action( 'wp_insert_plugin_card', 'wp_insert_abtesting_plugin_card', 90 ); |
| 4 |
function wp_insert_abtesting_plugin_card() { |
| 5 |
echo '<div class="plugin-card">'; |
| 6 |
echo '<div class="plugin-card-top">'; |
| 7 |
echo '<h4>Multiple Ad Networks / A-B Testing</h4>'; |
| 8 |
echo '<p>Multiple Ad Networks can be setup to display ads from different networks without infringing the terms of any network.'; |
| 9 |
echo 'At a time only ads from one network (Randomly Choosen) will be shown.'; |
| 10 |
echo 'This feature can also be used to randomly display different sized Ads from the same network.'; |
| 11 |
echo 'Please note that this option is global and applied to In-Post Ads, Ad Widgets and In-Theme Ads.</p>'; |
| 12 |
echo '</div>'; |
| 13 |
echo '<div class="plugin-card-bottom">'; |
| 14 |
echo '<p><a id="wp_insert_abtesting_configuration" href="javascript:;">Configuration</a></p>'; |
| 15 |
echo '</div>'; |
| 16 |
echo '</div>'; |
| 17 |
} |
| 18 |
/* End Add Card in Admin Panel */ |
| 19 |
|
| 20 |
/* Begin AB Testing Content */ |
| 21 |
add_action( 'wp_ajax_wp_insert_abtesting_configuration_form_get_content', 'wp_insert_abtesting_configuration_form_get_content' ); |
| 22 |
function wp_insert_abtesting_configuration_form_get_content() { |
| 23 |
check_ajax_referer( 'wp-insert', 'wp_insert_nonce' ); |
| 24 |
|
| 25 |
$abtestingMode = get_option( 'wp_insert_abtesting_mode', 1 ); |
| 26 |
$abtestingModes = [ |
| 27 |
[ |
| 28 |
'value' => '1', |
| 29 |
'text' => 'Primary Ad Network', |
| 30 |
], |
| 31 |
[ |
| 32 |
'value' => '2', |
| 33 |
'text' => 'Primary and Secondary Ad Networks', |
| 34 |
], |
| 35 |
[ |
| 36 |
'value' => '3', |
| 37 |
'text' => 'All Ad Networks', |
| 38 |
], |
| 39 |
]; |
| 40 |
echo '<div class="wp_insert_popup_content_wrapper">'; |
| 41 |
$control = new smartlogixControls( |
| 42 |
[ |
| 43 |
'type' => 'radio-group', |
| 44 |
'id' => 'wp_insert_abtesting_mode', |
| 45 |
'name' => 'wp_insert_abtesting_mode', |
| 46 |
'label' => 'Select the Ad Network Setup that best suits you', |
| 47 |
'value' => $abtestingMode, |
| 48 |
'options' => $abtestingModes, |
| 49 |
] |
| 50 |
); |
| 51 |
$control->add_control(); |
| 52 |
wp_insert_echo_html( $control->HTML ); |
| 53 |
echo '<p>'; |
| 54 |
echo '<b>Recommended Ad Networks</b><br /><br />'; |
| 55 |
echo '<a href="http://google.com/adsense" target="_blank"><img src="' . esc_url( WP_INSERT_URL . '/includes/assets/images/adsense-logo.png' ) . '" alt="Google AdSense" /></a>'; |
| 56 |
echo '</p>'; |
| 57 |
echo '</div>'; |
| 58 |
wp_die(); |
| 59 |
} |
| 60 |
|
| 61 |
add_action( 'wp_ajax_wp_insert_abtesting_configuration_form_save_action', 'wp_insert_abtesting_configuration_form_save_action' ); |
| 62 |
function wp_insert_abtesting_configuration_form_save_action() { |
| 63 |
check_ajax_referer( 'wp-insert', 'wp_insert_nonce' ); |
| 64 |
|
| 65 |
if ( isset( $_POST['wp_insert_abtesting_mode'] ) ) { |
| 66 |
$abtestingMode = sanitize_key( wp_unslash( $_POST['wp_insert_abtesting_mode'] ) ); |
| 67 |
if ( in_array( $abtestingMode, [ '1', '2', '3' ], true ) ) { |
| 68 |
update_option( 'wp_insert_abtesting_mode', $abtestingMode ); |
| 69 |
} |
| 70 |
} |
| 71 |
wp_die(); |
| 72 |
} |
| 73 |
/* End AB Testing Content */ |
| 74 |
|