gw_wpdb = & $wpdb; } function install_blocal_table() { global $wpdb; $return = false; //if ($wpdb->get_var("SHOW TABLES LIKE blocal_lead_capture") != 'blocal_lead_capture') { $table = "CREATE TABLE IF NOT EXISTS blocal_lead_capture( blocal_id int(11) NOT NULL AUTO_INCREMENT, blocal_name varchar(200) NOT NULL, blocal_email varchar(200) NOT NULL, blocal_contact varchar(200) NOT NULL, blocal_message varchar(255) NOT NULL, date datetime NOT NULL, PRIMARY KEY blocal_id(blocal_id) )ENGINE=InnoDB DEFAULT CHARSET=utf8;"; $wpdb->query($table); $return = true; //} return $return; } public function blocal_get_data(){ session_start(); if(isset($_POST['blocal_Submit'])){ $name = trim($_POST['blocal_name']); $email = trim($_POST['blocal_email']); $contact = trim($_POST['blocal_number']); $message = trim($_POST['blocal_comment']); $captcha = trim($_POST['captcha_code']); // code for check server side validation if( $name!='' && $email!='' && $contact!='' && $message!='' && $captcha!=''){ if( filter_var($email, FILTER_VALIDATE_EMAIL) ){ if(empty($_SESSION['captcha_code'] ) || strcasecmp($_SESSION['captcha_code'], $captcha) != 0){ $msg="The Captcha not match!";// Captcha verification is incorrect. }else{// Captcha verification is Correct. Final Code Execute here! $data = array( 'blocal_name' => $name, 'blocal_email' => $email, 'blocal_contact' => $contact, 'blocal_message' => $message, 'date' => date('Y-m-d h:i:s'), ); $this->insert_contactus_query($data); $msg="Thank you for contacting us."; $this->mail_to_admin($name, $email, $contact, $message); } }else{ $msg="Please enter valid email."; } }else{ $msg="Please fill all fields."; } return $msg; } } function insert_contactus_query($data) { $this->gw_wpdb->insert('blocal_lead_capture', $data); } function mail_to_admin($name, $email, $contact, $message){ $emailTo = get_option('tz_email'); if (!isset($emailTo) || ($emailTo == '')) { $emailTo = get_option('admin_email'); } $subject = 'New message from '. get_bloginfo() .' contact form.'; $body = "Congrats! Someone wants to connect with you, below are the details : \n\nName: $name \n\nEmail: $email \n\nContact No. : $contact \n\nMessage: $message"; wp_mail($emailTo, $subject, $body); } } if (!class_exists('WP_List_Table')) { require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); } class Leads_Table extends WP_List_Table { function __construct() { global $status, $page; parent::__construct(array( 'singular' => 'lead', 'plural' => 'leads', )); } function column_default($item, $column_name) { switch ($column_name) { case 'blocal_name': case 'blocal_email': case 'blocal_contact': case 'blocal_message': case 'date': return $item[$column_name]; default: return ''; } } function column_date($item) { return date('M d, Y h:i', strtotime($item['date'])); } function column_cb($item) { return sprintf( '', /* $1%s */ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie") /* $2%s */ $item['blocal_id'] //The value of the checkbox should be the record's id ); } function get_columns() { $columns = array(); $columns['cb'] = ''; $columns['blocal_name'] = __('Name', 'blocal'); $columns['blocal_email'] = __('Email', 'blocal'); $columns['blocal_contact'] = __('Contact Number', 'blocal'); $columns['blocal_message'] = __('Message', 'blocal'); $columns['date'] = __('Date', 'blocal'); $columns['actions'] = __('Action', 'blocal'); return $columns; } function get_sortable_columns() { $sortable_columns = array( 'blocal_name' => array('blocal_name', false), //true means it's already sorted 'blocal_email' => array('blocal_email', false), 'date' => array('date', false) ); return $sortable_columns; } function get_hidden_columns() { return array(); } function get_bulk_actions() { $actions = array( 'delete' => 'Delete' ); return $actions; } function process_bulk_action() { global $wpdb; if (isset($_POST['lead_delete_nonce']) && !empty($_POST['lead_delete_nonce'])) { $nonce = filter_input(INPUT_POST, 'lead_delete_nonce', FILTER_SANITIZE_STRING); $action = 'bulk-' . $this->_args['plural']; if (!wp_verify_nonce($nonce, $action)) wp_die('Nope! Security check failed!'); } $table_name = 'blocal_lead_capture'; $sendback = wp_get_referer(); if ('delete' === $this->current_action()) { $ids = isset($_POST['lead']) ? $_POST['lead'] : array(); if (is_array($ids)) $ids = implode(',', $ids); if (!empty($ids)) { $wpdb->query("DELETE FROM $table_name WHERE blocal_id IN($ids)"); } wp_redirect($sendback); } return; } public function column_actions($item) { $linkEdit = admin_url() . 'admin.php?page=blocal_leads&action=delete&id=' . $item['blocal_id']; $lead_id = 'delete_' . $item['blocal_id'] . '_' . wp_create_nonce('delete_' . $item['blocal_id']); $linkDel = '#deletelead_' . $item['blocal_id']; $actions = '
' . '' . __('Delete', 'blocal') . '' . '
'; return $actions; } function prepare_items() { global $wpdb; $per_page = 10; $columns = $this->get_columns(); $hidden = $this->get_hidden_columns(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); $this->process_bulk_action(); //$data = get_leads(); $data = get_leads('', 'ORDER BY date DESC'); function usort_reorder($a, $b) { $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'date'; //If no sort, default to title $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to desc $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order return ($order === 'desc') ? $result : -$result; //Send final sort direction to usort } usort($data, 'usort_reorder'); $current_page = $this->get_pagenum(); $total_items = count($data); $data = array_slice($data, (($current_page - 1) * $per_page), $per_page); $this->items = $data; $this->set_pagination_args(array( 'total_items' => $total_items, //WE have to calculate the total number of items 'per_page' => $per_page, //WE have to determine how many items to show on a page 'total_pages' => ceil($total_items / $per_page) //WE have to calculate the total number of pages )); } } function check_email_in_table($email) { if ($email != '') { $get_data = $this->gw_wpdb->get_row("SELECT * FROM blocal_lead_capture WHERE blocal_email = '$email'"); if (isset($get_data)) { return true; } else { return false; } } else { return false; } } function get_leads($where = '', $order = '', $limit = 0, $offset = 0) { global $wpdb; $table = 'blocal_lead_capture'; $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM $table WHERE 1=1"; if (!empty($where)) { $sql .= " AND $where"; } if (!empty($order)) { $sql .= " $order"; } if ($limit != 0) { $sql .= " LIMIT $limit OFFSET $offset"; } $results = $wpdb->get_results($sql, ARRAY_A); return $results; } function blocal_leads_table() { $leads_obj = new Leads_Table(); $leads_obj->prepare_items(); ?>

Blocal Leads

display(); ?>
delete($table, array('blocal_id' => $id[1])); echo 'Lead deleted successfully.'; die; } else { echo 'Somthing went wrong while deleting lead.'; die; } }