/** * check whether the current module should be displayed or not * * @return bool */ private function _check_ab_test_subject($ab_subject_id = false) { if (!$ab_subject_id) { return true; } $ab_subject_id = intval($ab_subject_id); $test_id = apply_filters('et_is_ab_testing_active_post_id', get_the_ID()); $test_id = (int) $test_id; // return false if the current ab module was processed already if (isset($this->ab_tests_processed[$test_id]) && $this->ab_tests_processed[$test_id]) { return false; } $user_unique_id = et_pb_get_visitor_id(); $saved_module_id = $this->_get_saved_ab_module_id($test_id, $user_unique_id); $current_ab_module_id = et_pb_ab_get_current_ab_module_id($test_id, $saved_module_id); // return false if current module is not the module which should be displayed this time if ((int) $current_ab_module_id !== (int) $ab_subject_id) { return false; } // mark current ab module as processed $this->ab_tests_processed[$test_id] = true; if (false === $saved_module_id) { // log the view_page event right away et_pb_add_stats_record(array('test_id' => $test_id, 'subject_id' => $ab_subject_id, 'record_type' => 'view_page')); // increment the module id for the next time et_pb_ab_increment_current_ab_module_id($test_id, $user_unique_id); } return true; }
function et_pb_ab_get_subject_id() { if (isset($_POST['et_frontend_nonce']) && !wp_verify_nonce($_POST['et_frontend_nonce'], 'et_frontend_nonce')) { die(-1); } $test_id = intval($_POST['et_pb_ab_test_id']); $user_unique_id = et_pb_get_visitor_id(); $saved_module_id = et_pb_ab_get_saved_ab_module_id($test_id, $user_unique_id); $current_ab_module_id = et_pb_ab_get_current_ab_module_id($test_id, $saved_module_id); $current_ab_module_id = intval($current_ab_module_id); if (false === $saved_module_id) { // log the view_page event et_pb_add_stats_record(array('test_id' => $test_id, 'subject_id' => $current_ab_module_id, 'record_type' => 'view_page')); // increment the module id for the next time et_pb_ab_increment_current_ab_module_id($test_id, $user_unique_id); } // retrieve the cached subjects HTML $subjects_cache = get_post_meta($test_id, 'et_pb_subjects_cache', true); $result = array('id' => $current_ab_module_id, 'content' => isset($subjects_cache[$current_ab_module_id]) ? $subjects_cache[$current_ab_module_id] : ''); die(json_encode($result)); }