| @@ -40,9 +40,10 @@ | ||
| 40 | 40 | 'all_time' => __( 'All time' ) |
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | 43 | if ( !defined ( 'FCA_EOI_DISABLE_STATS_TRACKING' )) { |
| 44 | - add_filter( 'request', array( $this, 'track_activity' ) ); | |
| 44 | + add_action( 'wp_ajax_fca_eoi_activity', array( $this, 'track_activity' ) ); | |
| 45 | + add_action( 'wp_ajax_nopriv_fca_eoi_activity', array( $this, 'track_activity' ) ); | |
| 45 | 46 | } |
| 46 | 47 | } |
| 47 | 48 | |
| 48 | 49 | public function get_text( $name, $category = null, $parameters = array() ) { |
| @@ -74,40 +75,27 @@ | ||
| 74 | 75 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 75 | 76 | dbDelta( $sql ); |
| 76 | 77 | } |
| 77 | 78 | |
| 78 | - public function get_tracking_code( $form_id, $escape = true ) { | |
| 79 | - ob_start(); | |
| 80 | - ?> | |
| 81 | - jQuery.post( <?php echo json_encode( trailingslashit( get_home_url() ) ) ?>, { | |
| 82 | - 'fca_eoi_track_form_id': <?php echo $escape ? json_encode( $form_id ) : $form_id ?> | |
| 83 | - } ); | |
| 84 | - <?php | |
| 85 | - return ob_get_clean(); | |
| 86 | - } | |
| 79 | + public function track_activity() { | |
| 80 | + | |
| 81 | + $nonce = sanitize_text_field( $_REQUEST['nonce'] ); | |
| 82 | + $form_id = intval( $_REQUEST['form_id'] ); | |
| 83 | + | |
| 84 | + $nonceVerified = wp_verify_nonce( $nonce, 'fca_eoi_activity') == 1; | |
| 85 | + $idVerified = is_int( $form_id ) && $form_id > 0; | |
| 86 | + | |
| 87 | + if ( $nonceVerified && $idVerified ) { | |
| 87 | 88 | |
| 88 | - public function track_activity( $request ) { | |
| 89 | - if ( empty( $_REQUEST['fca_eoi_track_form_id'] ) ) { | |
| 90 | - return $request; | |
| 91 | - } | |
| 92 | - | |
| 93 | - require_once FCA_EOI_PLUGIN_DIR . 'includes/classes/RobotDetector/RobotDetector.php'; | |
| 94 | - | |
| 95 | - $form_id = (int) $_REQUEST['fca_eoi_track_form_id']; | |
| 96 | - if ( get_post($form_id) ) { | |
| 89 | + require_once FCA_EOI_PLUGIN_DIR . 'includes/classes/RobotDetector/RobotDetector.php'; | |
| 97 | 90 | $robot_detector = new RobotDetector(); |
| 98 | - if ( ! $robot_detector->is_robot() ) { | |
| 99 | - if ( is_user_logged_in() ) { | |
| 100 | - /* USER IS LOGGED IN , DON'T COUNT AS IMPRESSION */ | |
| 101 | - }else { | |
| 102 | - $this->add_impression( $form_id ); | |
| 103 | - } | |
| 104 | - | |
| 91 | + | |
| 92 | + if ( get_post( $form_id ) && !is_user_logged_in() && !$robot_detector->is_robot() ) { | |
| 93 | + $this->add_impression( $form_id ); | |
| 94 | + wp_send_json_success( $form_id ); | |
| 105 | 95 | } |
| 106 | - } | |
| 107 | - | |
| 108 | - exit; | |
| 109 | - | |
| 96 | + } | |
| 97 | + wp_send_json_error(); | |
| 110 | 98 | |
| 111 | 99 | } |
| 112 | 100 | |
| 113 | 101 | public function format_column_text( $column_name, $value ) { |