__( 'Invalid contact type.', 'adct-tracking-template' ) ), 400 ); } $is_site_wide = in_array( $contact_type, self::SITEWIDE_CONTACT_TYPES, true ); if ( $is_site_wide ) { if ( $product_id && 'product' !== get_post_type( $product_id ) ) { $product_id = 0; } } elseif ( ! $product_id || 'product' !== get_post_type( $product_id ) ) { wp_send_json_error( array( 'message' => __( 'Invalid product.', 'adct-tracking-template' ) ), 400 ); } $product_title = isset( $_POST['product_title'] ) ? sanitize_text_field( wp_unslash( $_POST['product_title'] ) ) : ''; $product_url = isset( $_POST['product_url'] ) ? esc_url_raw( wp_unslash( $_POST['product_url'] ) ) : ''; if ( $product_id ) { if ( '' === $product_title ) { $product_title = get_the_title( $product_id ); } if ( '' === $product_url ) { $product_url = get_permalink( $product_id ); } } $saved = ADCT_Database::insert_click( array( 'product_id' => $product_id, 'product_title' => $product_title, 'product_url' => $product_url, 'agent_id' => isset( $_POST['agent_id'] ) ? sanitize_text_field( wp_unslash( $_POST['agent_id'] ) ) : '', 'agent_name' => isset( $_POST['agent_name'] ) ? sanitize_text_field( wp_unslash( $_POST['agent_name'] ) ) : '', 'contact_type' => $contact_type, 'clicked_value' => isset( $_POST['clicked_value'] ) ? sanitize_text_field( wp_unslash( $_POST['clicked_value'] ) ) : '', 'source' => isset( $_POST['source'] ) ? sanitize_key( wp_unslash( $_POST['source'] ) ) : '', 'landing_url' => isset( $_POST['landing_url'] ) ? esc_url_raw( wp_unslash( $_POST['landing_url'] ) ) : '', 'landing_path' => isset( $_POST['landing_path'] ) ? sanitize_text_field( wp_unslash( $_POST['landing_path'] ) ) : '', 'landing_referrer' => isset( $_POST['landing_referrer'] ) ? sanitize_text_field( wp_unslash( $_POST['landing_referrer'] ) ) : '', 'entry_source' => isset( $_POST['entry_source'] ) ? sanitize_key( wp_unslash( $_POST['entry_source'] ) ) : '', 'utm_source' => isset( $_POST['utm_source'] ) ? sanitize_text_field( wp_unslash( $_POST['utm_source'] ) ) : '', 'utm_medium' => isset( $_POST['utm_medium'] ) ? sanitize_text_field( wp_unslash( $_POST['utm_medium'] ) ) : '', 'utm_campaign' => isset( $_POST['utm_campaign'] ) ? sanitize_text_field( wp_unslash( $_POST['utm_campaign'] ) ) : '', 'utm_id' => isset( $_POST['utm_id'] ) ? sanitize_text_field( wp_unslash( $_POST['utm_id'] ) ) : '', 'utm_term' => isset( $_POST['utm_term'] ) ? sanitize_text_field( wp_unslash( $_POST['utm_term'] ) ) : '', 'utm_content' => isset( $_POST['utm_content'] ) ? sanitize_text_field( wp_unslash( $_POST['utm_content'] ) ) : '', 'gclid' => isset( $_POST['gclid'] ) ? sanitize_text_field( wp_unslash( $_POST['gclid'] ) ) : '', 'duration_seconds' => isset( $_POST['duration_seconds'] ) ? absint( wp_unslash( $_POST['duration_seconds'] ) ) : 0, 'session_id' => isset( $_POST['session_id'] ) ? sanitize_text_field( wp_unslash( $_POST['session_id'] ) ) : '', ) ); if ( ! $saved ) { wp_send_json_error( array( 'message' => __( 'Could not save click.', 'adct-tracking-template' ) ), 500 ); } wp_send_json_success( array( 'logged' => true ) ); } }