function set_enp_button_allow_data_tracking($value) { if (empty($value)) { // return notification to pleeeease turn this value on add_settings_error('enp-nag-for-data', 'enp-nag', 'Please turn on "Allow data collection" so that we can continue to provide high-quality, open-source plugins. We will only use your Engaging Button data anonymously for research with the Engaging News Project.', 'error'); } elseif ($value === '1') { // check to see if it already was on 1 $old_allow_data_tracking_value = get_option('enp_button_allow_data_tracking'); // if it doesn't equal 1, then we should send it over if ($old_allow_data_tracking_value != 1) { // send all current data since they just turned it on $send_data = new Enp_Send_Data(); $send_data->send_all_engaging_data(); } } return $value; }
function enp_send_button_count() { $pid = $_REQUEST['pid']; $btn_slug = $_REQUEST['slug']; $btn_type = $_REQUEST['type']; // post or comment? We don't need the specific post type // Instantiate WP_Ajax_Response $response = new WP_Ajax_Response(); // check to see if they're allowing us to collect data. $send_enp_data = get_option('enp_button_allow_data_tracking'); if ($send_enp_data === '1') { // url if ($btn_type == 'comment') { $button_url = get_comment_link($pid); } else { $button_url = get_permalink($pid); } // send the data to engaging news project for research $data = array('button_id' => $pid, 'slug' => $btn_slug, 'type' => $btn_type, 'button_url' => $button_url); $send = new Enp_Send_Data(); $send->send_click_data($data); $response->add(array('data' => 'success', 'supplemental' => array('message' => 'Click data has been sent to the Engaging News Project.'))); } else { $response->add(array('data' => 'error', 'supplemental' => array('message' => 'Sending click data is disabled.'))); } // Send the response back $response->send(); // Always end with an exit on ajax exit; }