Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-conte.../themes/Divi/includes/builder
File: ab-testing.php
die( -1 );
[1000] Fix | Delete
}
[1001] Fix | Delete
[1002] Fix | Delete
global $wpdb;
[1003] Fix | Delete
[1004] Fix | Delete
$stats_table_name = $wpdb->prefix . 'et_divi_ab_testing_stats';
[1005] Fix | Delete
$wpdb->et_divi_ab_testing_stats = $stats_table_name;
[1006] Fix | Delete
$client_subject_table_name = $wpdb->prefix . 'et_divi_ab_testing_clients';
[1007] Fix | Delete
$wpdb->et_divi_ab_testing_clients = $client_subject_table_name;
[1008] Fix | Delete
[1009] Fix | Delete
/*
[1010] Fix | Delete
* We'll set the default character set and collation for this table.
[1011] Fix | Delete
* If we don't do this, some characters could end up being converted
[1012] Fix | Delete
* to just ?'s when saved in our table.
[1013] Fix | Delete
*/
[1014] Fix | Delete
$charset_collate = '';
[1015] Fix | Delete
[1016] Fix | Delete
if ( ! empty( $wpdb->charset ) ) {
[1017] Fix | Delete
$charset_collate = sprintf(
[1018] Fix | Delete
'DEFAULT CHARACTER SET %1$s',
[1019] Fix | Delete
sanitize_text_field( $wpdb->charset )
[1020] Fix | Delete
);
[1021] Fix | Delete
}
[1022] Fix | Delete
[1023] Fix | Delete
if ( ! empty( $wpdb->collate ) ) {
[1024] Fix | Delete
$charset_collate .= sprintf(
[1025] Fix | Delete
' COLLATE %1$s',
[1026] Fix | Delete
sanitize_text_field( $wpdb->collate )
[1027] Fix | Delete
);
[1028] Fix | Delete
}
[1029] Fix | Delete
[1030] Fix | Delete
$ab_tables_queries = array();
[1031] Fix | Delete
[1032] Fix | Delete
// Remove client_id column from stats table
[1033] Fix | Delete
if ( 0 < $wpdb->query( "SHOW COLUMNS FROM `$wpdb->et_divi_ab_testing_stats` LIKE 'client_id'" ) ) {
[1034] Fix | Delete
$wpdb->query( "ALTER TABLE `$wpdb->et_divi_ab_testing_stats` DROP COLUMN client_id" );
[1035] Fix | Delete
}
[1036] Fix | Delete
[1037] Fix | Delete
// Remove client subject table
[1038] Fix | Delete
if ( 0 < $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->et_divi_ab_testing_clients ) ) ) {
[1039] Fix | Delete
$wpdb->query( "DROP TABLE $wpdb->et_divi_ab_testing_clients" );
[1040] Fix | Delete
}
[1041] Fix | Delete
[1042] Fix | Delete
$ab_tables_queries[] = "CREATE TABLE $wpdb->et_divi_ab_testing_stats (
[1043] Fix | Delete
id mediumint(9) NOT NULL AUTO_INCREMENT,
[1044] Fix | Delete
test_id varchar(20) NOT NULL,
[1045] Fix | Delete
subject_id varchar(20) NOT NULL,
[1046] Fix | Delete
record_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
[1047] Fix | Delete
event varchar(10) NOT NULL,
[1048] Fix | Delete
UNIQUE KEY id (id)
[1049] Fix | Delete
) $charset_collate;";
[1050] Fix | Delete
[1051] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
[1052] Fix | Delete
[1053] Fix | Delete
dbDelta( $ab_tables_queries );
[1054] Fix | Delete
[1055] Fix | Delete
$db_settings = array(
[1056] Fix | Delete
'db_version' => ET_PB_AB_DB_VERSION,
[1057] Fix | Delete
);
[1058] Fix | Delete
[1059] Fix | Delete
update_option( 'et_pb_ab_test_settings', $db_settings );
[1060] Fix | Delete
[1061] Fix | Delete
// Register AB Testing cron
[1062] Fix | Delete
et_pb_create_ab_cron();
[1063] Fix | Delete
[1064] Fix | Delete
unset( $wpdb->et_divi_ab_testing_stats );
[1065] Fix | Delete
unset( $wpdb->et_divi_ab_testing_clients );
[1066] Fix | Delete
[1067] Fix | Delete
die( 'success' );
[1068] Fix | Delete
}
[1069] Fix | Delete
add_action( 'wp_ajax_et_pb_create_ab_tables', 'et_pb_create_ab_tables' );
[1070] Fix | Delete
[1071] Fix | Delete
/**
[1072] Fix | Delete
* Handle adding the AB testing log record via ajax
[1073] Fix | Delete
*
[1074] Fix | Delete
* @return void
[1075] Fix | Delete
*/
[1076] Fix | Delete
function et_pb_update_stats_table() {
[1077] Fix | Delete
if ( ! isset( $_POST['et_ab_log_nonce'] ) || ! wp_verify_nonce( $_POST['et_ab_log_nonce'], 'et_ab_testing_log_nonce' ) ) {
[1078] Fix | Delete
die( -1 );
[1079] Fix | Delete
}
[1080] Fix | Delete
[1081] Fix | Delete
$stats_data_json = str_replace( '\\', '', $_POST['stats_data_array'] );
[1082] Fix | Delete
$stats_data_array = json_decode( $stats_data_json, true );
[1083] Fix | Delete
[1084] Fix | Delete
et_pb_add_stats_record( $stats_data_array );
[1085] Fix | Delete
[1086] Fix | Delete
die( 1 );
[1087] Fix | Delete
}
[1088] Fix | Delete
add_action( 'wp_ajax_et_pb_update_stats_table', 'et_pb_update_stats_table' );
[1089] Fix | Delete
add_action( 'wp_ajax_nopriv_et_pb_update_stats_table', 'et_pb_update_stats_table' );
[1090] Fix | Delete
[1091] Fix | Delete
/**
[1092] Fix | Delete
* List of valid AB Testing refresh interval duration
[1093] Fix | Delete
*
[1094] Fix | Delete
* @return array
[1095] Fix | Delete
*/
[1096] Fix | Delete
function et_pb_ab_refresh_interval_durations() {
[1097] Fix | Delete
return apply_filters( 'et_pb_ab_refresh_interval_durations', array(
[1098] Fix | Delete
'hourly' => 'day',
[1099] Fix | Delete
'daily' => 'week',
[1100] Fix | Delete
));
[1101] Fix | Delete
}
[1102] Fix | Delete
[1103] Fix | Delete
/**
[1104] Fix | Delete
* Get refresh interval of particular AB Testing
[1105] Fix | Delete
*
[1106] Fix | Delete
* @param int post ID
[1107] Fix | Delete
* @param string default interval
[1108] Fix | Delete
* @return string interval used in particular AB Testing
[1109] Fix | Delete
*/
[1110] Fix | Delete
function et_pb_ab_get_refresh_interval( $post_id, $default = 'hourly' ) {
[1111] Fix | Delete
$interval = get_post_meta( $post_id, '_et_pb_ab_stats_refresh_interval', true );
[1112] Fix | Delete
[1113] Fix | Delete
if ( in_array( $interval, array_keys( et_pb_ab_refresh_interval_durations() ) ) ) {
[1114] Fix | Delete
return apply_filters( 'et_pb_ab_get_refresh_interval', $interval, $post_id );
[1115] Fix | Delete
}
[1116] Fix | Delete
[1117] Fix | Delete
return apply_filters( 'et_pb_ab_default_refresh_interval', $default, $post_id );
[1118] Fix | Delete
}
[1119] Fix | Delete
[1120] Fix | Delete
/**
[1121] Fix | Delete
* Get refresh interval duration of particular AB Testing
[1122] Fix | Delete
*
[1123] Fix | Delete
* @param int post ID
[1124] Fix | Delete
* @param string default interval duration
[1125] Fix | Delete
* @return string test's interval duration
[1126] Fix | Delete
*/
[1127] Fix | Delete
function et_pb_ab_get_refresh_interval_duration( $post_id, $default = 'day' ) {
[1128] Fix | Delete
$durations = et_pb_ab_refresh_interval_durations();
[1129] Fix | Delete
[1130] Fix | Delete
$interval = et_pb_ab_get_refresh_interval( $post_id );
[1131] Fix | Delete
[1132] Fix | Delete
$interval_duration = isset( $durations[ $interval ] ) ? $durations[ $interval ] : $default;
[1133] Fix | Delete
[1134] Fix | Delete
return apply_filters( 'et_pb_ab_get_refresh_interval_duration', $interval_duration, $post_id );
[1135] Fix | Delete
}
[1136] Fix | Delete
[1137] Fix | Delete
/**
[1138] Fix | Delete
* Get goal module slug of particular AB Testing
[1139] Fix | Delete
*
[1140] Fix | Delete
* @param int post ID
[1141] Fix | Delete
* @return string test's goal module slug
[1142] Fix | Delete
*/
[1143] Fix | Delete
function et_pb_ab_get_goal_module( $post_id ) {
[1144] Fix | Delete
return get_post_meta( $post_id, '_et_pb_ab_goal_module', true );
[1145] Fix | Delete
}
[1146] Fix | Delete
[1147] Fix | Delete
/**
[1148] Fix | Delete
* Register Divi's AB Testing cron
[1149] Fix | Delete
* There are 2 options - daily and hourly, so schedule 2 events
[1150] Fix | Delete
* @return void
[1151] Fix | Delete
*/
[1152] Fix | Delete
function et_pb_create_ab_cron() {
[1153] Fix | Delete
// schedule daily event
[1154] Fix | Delete
if ( ! wp_next_scheduled( 'et_pb_ab_cron', array( 'interval' => 'daily' ) ) ) {
[1155] Fix | Delete
wp_schedule_event( time(), 'daily', 'et_pb_ab_cron', array( 'interval' => 'daily' ) );
[1156] Fix | Delete
}
[1157] Fix | Delete
[1158] Fix | Delete
// schedule hourly event
[1159] Fix | Delete
if ( ! wp_next_scheduled( 'et_pb_ab_cron', array( 'interval' => 'hourly' ) ) ) {
[1160] Fix | Delete
wp_schedule_event( time(), 'hourly', 'et_pb_ab_cron', array( 'interval' => 'hourly' ) );
[1161] Fix | Delete
}
[1162] Fix | Delete
}
[1163] Fix | Delete
[1164] Fix | Delete
/**
[1165] Fix | Delete
* Perform Divi's AB Testing cron
[1166] Fix | Delete
*
[1167] Fix | Delete
* @return void
[1168] Fix | Delete
*/
[1169] Fix | Delete
function et_pb_ab_cron( $args ) {
[1170] Fix | Delete
$all_tests = et_pb_ab_get_all_tests();
[1171] Fix | Delete
$interval = isset( $args ) ? $args : 'hourly';
[1172] Fix | Delete
[1173] Fix | Delete
if ( empty( $all_tests ) ) {
[1174] Fix | Delete
return;
[1175] Fix | Delete
}
[1176] Fix | Delete
[1177] Fix | Delete
// update cache for each test and for each duration
[1178] Fix | Delete
foreach ( $all_tests as $test ) {
[1179] Fix | Delete
$current_test_interval = et_pb_ab_get_refresh_interval( $test['test_id'] );
[1180] Fix | Delete
[1181] Fix | Delete
// determine whether or not we should update the stats for current test depending on interval parameter
[1182] Fix | Delete
if ( $current_test_interval !== $interval ) {
[1183] Fix | Delete
continue;
[1184] Fix | Delete
}
[1185] Fix | Delete
[1186] Fix | Delete
foreach ( et_pb_ab_get_stats_data_duration() as $duration ) {
[1187] Fix | Delete
et_pb_ab_get_stats_data( $test['test_id'], $duration, false, true, true );
[1188] Fix | Delete
}
[1189] Fix | Delete
}
[1190] Fix | Delete
}
[1191] Fix | Delete
add_action( 'et_pb_ab_cron', 'et_pb_ab_cron' );
[1192] Fix | Delete
[1193] Fix | Delete
function et_pb_ab_clear_cache_handler( $test_id ) {
[1194] Fix | Delete
if ( ! $test_id ) {
[1195] Fix | Delete
return;
[1196] Fix | Delete
}
[1197] Fix | Delete
[1198] Fix | Delete
foreach ( et_pb_ab_get_stats_data_duration() as $duration ) {
[1199] Fix | Delete
delete_transient( 'et_pb_ab_' . $test_id . '_stats_' . $duration );
[1200] Fix | Delete
}
[1201] Fix | Delete
}
[1202] Fix | Delete
[1203] Fix | Delete
function et_pb_ab_clear_cache() {
[1204] Fix | Delete
// Verify nonce
[1205] Fix | Delete
if ( ! isset( $_POST['et_pb_ab_nonce'] ) || ! wp_verify_nonce( $_POST['et_pb_ab_nonce'], 'ab_testing_builder_nonce' ) ) {
[1206] Fix | Delete
die( -1 );
[1207] Fix | Delete
}
[1208] Fix | Delete
[1209] Fix | Delete
$test_id = ! empty( $_POST['et_pb_test_id'] ) ? intval( $_POST['et_pb_test_id'] ) : '';
[1210] Fix | Delete
[1211] Fix | Delete
// Verify user permission
[1212] Fix | Delete
if ( empty( $test_id ) || ! current_user_can( 'edit_post', $test_id ) || ! et_pb_is_allowed( 'ab_testing' ) ) {
[1213] Fix | Delete
die( -1 );
[1214] Fix | Delete
}
[1215] Fix | Delete
[1216] Fix | Delete
et_pb_ab_clear_cache_handler( $test_id );
[1217] Fix | Delete
[1218] Fix | Delete
// VB ask to load data to save request
[1219] Fix | Delete
if ( isset( $_POST['et_pb_ab_load_data'] ) && isset( $_POST['et_pb_test_id'] ) && isset( $_POST['et_pb_ab_duration'] ) ) {
[1220] Fix | Delete
// Allowlist the duration value
[1221] Fix | Delete
$duration = in_array( $_POST['et_pb_ab_duration'], et_pb_ab_get_stats_data_duration() ) ? $_POST['et_pb_ab_duration'] : 'day';
[1222] Fix | Delete
[1223] Fix | Delete
// Get data
[1224] Fix | Delete
$output = et_pb_ab_get_stats_data( intval( $_POST['et_pb_test_id'] ), $duration );
[1225] Fix | Delete
[1226] Fix | Delete
// Print output
[1227] Fix | Delete
die( wp_json_encode( $output ) );
[1228] Fix | Delete
}
[1229] Fix | Delete
[1230] Fix | Delete
die( 1 );
[1231] Fix | Delete
}
[1232] Fix | Delete
[1233] Fix | Delete
add_action( 'wp_ajax_et_pb_ab_clear_cache', 'et_pb_ab_clear_cache' );
[1234] Fix | Delete
[1235] Fix | Delete
function et_pb_ab_get_all_tests() {
[1236] Fix | Delete
global $wpdb;
[1237] Fix | Delete
[1238] Fix | Delete
$wpdb->et_divi_ab_testing_stats = $wpdb->prefix . 'et_divi_ab_testing_stats';
[1239] Fix | Delete
[1240] Fix | Delete
// do nothing if no stats table exists in current WP
[1241] Fix | Delete
if ( ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->et_divi_ab_testing_stats'" ) ) {
[1242] Fix | Delete
return false;
[1243] Fix | Delete
}
[1244] Fix | Delete
[1245] Fix | Delete
// construct sql query to get all the test ID from db
[1246] Fix | Delete
$sql = "SELECT DISTINCT test_id FROM `$wpdb->et_divi_ab_testing_stats`";
[1247] Fix | Delete
[1248] Fix | Delete
// cache the data from conversions table
[1249] Fix | Delete
$all_tests = $wpdb->get_results( $sql, ARRAY_A ); // WPCS: unprepared SQL okay, value of $sql was prepared above.
[1250] Fix | Delete
[1251] Fix | Delete
unset( $wpdb->et_divi_ab_testing_stats );
[1252] Fix | Delete
[1253] Fix | Delete
return $all_tests;
[1254] Fix | Delete
}
[1255] Fix | Delete
[1256] Fix | Delete
function et_pb_ab_clear_stats() {
[1257] Fix | Delete
// Verify nonce
[1258] Fix | Delete
if ( ! isset( $_POST['et_pb_ab_nonce'] ) || ! wp_verify_nonce( $_POST['et_pb_ab_nonce'], 'ab_testing_builder_nonce' ) ) {
[1259] Fix | Delete
die( -1 );
[1260] Fix | Delete
}
[1261] Fix | Delete
[1262] Fix | Delete
$test_id = ! empty( $_POST['et_pb_test_id'] ) ? intval( $_POST['et_pb_test_id'] ) : '';
[1263] Fix | Delete
[1264] Fix | Delete
// Verify user permission
[1265] Fix | Delete
if ( empty( $test_id ) || ! current_user_can( 'edit_post', $test_id ) || ! et_pb_is_allowed( 'ab_testing' ) ) {
[1266] Fix | Delete
die( -1 );
[1267] Fix | Delete
}
[1268] Fix | Delete
[1269] Fix | Delete
et_pb_ab_remove_stats( $test_id );
[1270] Fix | Delete
[1271] Fix | Delete
et_pb_ab_clear_cache_handler( $test_id );
[1272] Fix | Delete
[1273] Fix | Delete
die( 1 );
[1274] Fix | Delete
}
[1275] Fix | Delete
add_action( 'wp_ajax_et_pb_ab_clear_stats', 'et_pb_ab_clear_stats' );
[1276] Fix | Delete
[1277] Fix | Delete
/**
[1278] Fix | Delete
* Remove AB Testing log and clear stats cache
[1279] Fix | Delete
*
[1280] Fix | Delete
* @param int post ID
[1281] Fix | Delete
* @return void
[1282] Fix | Delete
*/
[1283] Fix | Delete
function et_pb_ab_remove_stats( $test_id ) {
[1284] Fix | Delete
global $wpdb;
[1285] Fix | Delete
[1286] Fix | Delete
$test_id = intval( $test_id );
[1287] Fix | Delete
[1288] Fix | Delete
et_pb_ab_clear_cache_handler( $test_id );
[1289] Fix | Delete
[1290] Fix | Delete
$sql_args = array(
[1291] Fix | Delete
$test_id,
[1292] Fix | Delete
);
[1293] Fix | Delete
[1294] Fix | Delete
$wpdb->et_divi_ab_testing_stats = $wpdb->prefix . 'et_divi_ab_testing_stats';
[1295] Fix | Delete
[1296] Fix | Delete
// do nothing if no stats table exists in current WP
[1297] Fix | Delete
if ( ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->et_divi_ab_testing_stats'" ) ) {
[1298] Fix | Delete
return false;
[1299] Fix | Delete
}
[1300] Fix | Delete
[1301] Fix | Delete
// construct sql query to remove value from DB table
[1302] Fix | Delete
$sql = "DELETE FROM `$wpdb->et_divi_ab_testing_stats` WHERE test_id = %d";
[1303] Fix | Delete
[1304] Fix | Delete
$wpdb->query( $wpdb->prepare( $sql, $sql_args ) ); // WPCS: unprepared SQL okay, value of $sql was prepared above.
[1305] Fix | Delete
[1306] Fix | Delete
unset( $wpdb->et_divi_ab_testing_stats );
[1307] Fix | Delete
}
[1308] Fix | Delete
[1309] Fix | Delete
/**
[1310] Fix | Delete
* Shop trigger DOM
[1311] Fix | Delete
*
[1312] Fix | Delete
* @return void
[1313] Fix | Delete
*/
[1314] Fix | Delete
function et_pb_ab_shop_trigger() {
[1315] Fix | Delete
echo '<div class="et_pb_ab_shop_conversion"></div>';
[1316] Fix | Delete
}
[1317] Fix | Delete
add_action( 'woocommerce_thankyou', 'et_pb_ab_shop_trigger' );
[1318] Fix | Delete
[1319] Fix | Delete
/**
[1320] Fix | Delete
* Tracking shortcode
[1321] Fix | Delete
*
[1322] Fix | Delete
* @return void
[1323] Fix | Delete
*/
[1324] Fix | Delete
function et_pb_split_track( $atts ) {
[1325] Fix | Delete
$settings = shortcode_atts( array(
[1326] Fix | Delete
'id' => '',
[1327] Fix | Delete
), $atts );
[1328] Fix | Delete
[1329] Fix | Delete
$output = sprintf( '<div class="et_pb_ab_split_track" style="display:none;" data-test_id="%1$s"></div>',
[1330] Fix | Delete
esc_attr( $settings['id'] )
[1331] Fix | Delete
);
[1332] Fix | Delete
[1333] Fix | Delete
return $output;
[1334] Fix | Delete
}
[1335] Fix | Delete
add_shortcode( 'et_pb_split_track', 'et_pb_split_track' );
[1336] Fix | Delete
[1337] Fix | Delete
/**
[1338] Fix | Delete
* Get all posts loaded for the current request that have AB testing enabled.
[1339] Fix | Delete
* This includes TB layouts and the current post, if any.
[1340] Fix | Delete
*
[1341] Fix | Delete
* @since 4.0
[1342] Fix | Delete
*
[1343] Fix | Delete
* @return integer[]
[1344] Fix | Delete
*/
[1345] Fix | Delete
function et_builder_ab_get_current_tests() {
[1346] Fix | Delete
$layouts = et_theme_builder_get_template_layouts();
[1347] Fix | Delete
$posts = array();
[1348] Fix | Delete
$tests = array();
[1349] Fix | Delete
[1350] Fix | Delete
foreach ( $layouts as $layout ) {
[1351] Fix | Delete
if ( is_array( $layout ) && $layout['override'] ) {
[1352] Fix | Delete
$posts[] = $layout['id'];
[1353] Fix | Delete
}
[1354] Fix | Delete
}
[1355] Fix | Delete
[1356] Fix | Delete
if ( is_singular() ) {
[1357] Fix | Delete
$posts[] = get_the_ID();
[1358] Fix | Delete
}
[1359] Fix | Delete
[1360] Fix | Delete
foreach ( $posts as $post_id ) {
[1361] Fix | Delete
if ( et_pb_is_pagebuilder_used( $post_id ) && et_is_ab_testing_active( $post_id ) ) {
[1362] Fix | Delete
$tests[] = array(
[1363] Fix | Delete
'post_id' => $post_id,
[1364] Fix | Delete
'test_id' => get_post_meta( $post_id, '_et_pb_ab_testing_id', true ),
[1365] Fix | Delete
);
[1366] Fix | Delete
}
[1367] Fix | Delete
}
[1368] Fix | Delete
[1369] Fix | Delete
return $tests;
[1370] Fix | Delete
}
[1371] Fix | Delete
[1372] Fix | Delete
/**
[1373] Fix | Delete
* Initialize AB Testing. Check whether the user has visited the page or not by checking its cookie
[1374] Fix | Delete
*
[1375] Fix | Delete
* @since
[1376] Fix | Delete
*
[1377] Fix | Delete
* @return void
[1378] Fix | Delete
*/
[1379] Fix | Delete
function et_pb_ab_init() {
[1380] Fix | Delete
$tests = et_builder_ab_get_current_tests();
[1381] Fix | Delete
[1382] Fix | Delete
foreach ( $tests as $test ) {
[1383] Fix | Delete
et_builder_ab_initialize_for_post( $test['post_id'] );
[1384] Fix | Delete
}
[1385] Fix | Delete
}
[1386] Fix | Delete
add_action( 'wp', 'et_pb_ab_init' );
[1387] Fix | Delete
[1388] Fix | Delete
/**
[1389] Fix | Delete
* Initialize AB testing for the specified post.
[1390] Fix | Delete
*
[1391] Fix | Delete
* @since 4.0
[1392] Fix | Delete
*
[1393] Fix | Delete
* @param integer $post_id
[1394] Fix | Delete
*
[1395] Fix | Delete
* @return void
[1396] Fix | Delete
*/
[1397] Fix | Delete
function et_builder_ab_initialize_for_post( $post_id ) {
[1398] Fix | Delete
global $et_pb_ab_subject;
[1399] Fix | Delete
[1400] Fix | Delete
if ( ! is_array( $et_pb_ab_subject ) ) {
[1401] Fix | Delete
$et_pb_ab_subject = array();
[1402] Fix | Delete
}
[1403] Fix | Delete
[1404] Fix | Delete
$ab_subjects = et_pb_ab_get_subjects( $post_id );
[1405] Fix | Delete
$ab_hash_key = defined( 'NONCE_SALT' ) ? NONCE_SALT : 'default-divi-hash-key';
[1406] Fix | Delete
$hashed_subject_id = et_pb_ab_get_visitor_cookie( $post_id, 'view_page' );
[1407] Fix | Delete
[1408] Fix | Delete
if ( $hashed_subject_id ) {
[1409] Fix | Delete
// Compare subjects against hashed subject id found on cookie to verify whether cookie value is valid or not
[1410] Fix | Delete
foreach ( $ab_subjects as $ab_subject ) {
[1411] Fix | Delete
// Valid subject_id is found
[1412] Fix | Delete
if ( hash_hmac( 'md5', $ab_subject, $ab_hash_key ) === $hashed_subject_id ) {
[1413] Fix | Delete
$et_pb_ab_subject[ $post_id ] = $ab_subject;
[1414] Fix | Delete
[1415] Fix | Delete
// no need to continue
[1416] Fix | Delete
break;
[1417] Fix | Delete
}
[1418] Fix | Delete
}
[1419] Fix | Delete
[1420] Fix | Delete
// If no valid subject found, get the first one
[1421] Fix | Delete
if ( isset( $ab_subjects[0] ) && ! et_()->array_get( $et_pb_ab_subject, $post_id, '' ) ) {
[1422] Fix | Delete
$et_pb_ab_subject[ $post_id ] = $ab_subjects[0];
[1423] Fix | Delete
}
[1424] Fix | Delete
} else {
[1425] Fix | Delete
// First visit. Get next subject on queue
[1426] Fix | Delete
$next_subject_index = get_post_meta( $post_id, '_et_pb_ab_next_subject' , true );
[1427] Fix | Delete
[1428] Fix | Delete
// Get current subject index based on `_et_pb_ab_next_subject` post meta value
[1429] Fix | Delete
$subject_index = false !== $next_subject_index && isset( $ab_subjects[ $next_subject_index ] ) ? (int) $next_subject_index : 0;
[1430] Fix | Delete
[1431] Fix | Delete
// Get current subject index
[1432] Fix | Delete
$et_pb_ab_subject[ $post_id ] = $ab_subjects[ $subject_index ];
[1433] Fix | Delete
[1434] Fix | Delete
// Hash the subject
[1435] Fix | Delete
$hashed_subject_id = hash_hmac( 'md5', $et_pb_ab_subject[ $post_id ], $ab_hash_key );
[1436] Fix | Delete
[1437] Fix | Delete
// Set cookie for returning visit
[1438] Fix | Delete
et_pb_ab_set_visitor_cookie( $post_id, 'view_page', $hashed_subject_id );
[1439] Fix | Delete
[1440] Fix | Delete
// Bump subject index and save on post meta for next visitor
[1441] Fix | Delete
et_pb_ab_increment_current_ab_module_id( $post_id );
[1442] Fix | Delete
[1443] Fix | Delete
// log the view_page event right away
[1444] Fix | Delete
$is_et_fb_enabled = function_exists( 'et_fb_enabled' ) && et_fb_enabled();
[1445] Fix | Delete
[1446] Fix | Delete
if ( ! is_admin() && ! $is_et_fb_enabled ) {
[1447] Fix | Delete
et_pb_add_stats_record( array(
[1448] Fix | Delete
'test_id' => $post_id,
[1449] Fix | Delete
'subject_id' => $et_pb_ab_subject[ $post_id ],
[1450] Fix | Delete
'record_type' => 'view_page',
[1451] Fix | Delete
)
[1452] Fix | Delete
);
[1453] Fix | Delete
}
[1454] Fix | Delete
}
[1455] Fix | Delete
}
[1456] Fix | Delete
[1457] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function