SwpmUtils::_('Membership Level'), 'plural' => SwpmUtils::_('Membership Levels'), 'ajax' => false )); } function get_columns() { return array( 'cb' => '' , 'id' => SwpmUtils::_('ID') , 'alias' => SwpmUtils::_('Membership Level') , 'role' => SwpmUtils::_('Role') , 'valid_for' => SwpmUtils::_('Access Valid For/Until') ); } function get_sortable_columns() { return array( 'id' => array('id', true), 'alias' => array('alias', true) ); } function get_bulk_actions() { $actions = array( 'bulk_delete' => SwpmUtils::_('Delete') ); return $actions; } function column_default($item, $column_name) { if ($column_name == 'valid_for') { if ($item['subscription_duration_type'] == SwpmMembershipLevel::NO_EXPIRY) { return 'No Expiry'; } if ($item['subscription_duration_type'] == SwpmMembershipLevel::FIXED_DATE) { $formatted_date = SwpmUtils::get_formatted_date_according_to_wp_settings($item['subscription_period']); return $formatted_date; } if ($item['subscription_duration_type'] == SwpmMembershipLevel::DAYS) { return $item['subscription_period'] . " Day(s)"; } if ($item['subscription_duration_type'] == SwpmMembershipLevel::WEEKS) { return $item['subscription_period'] . " Week(s)"; } if ($item['subscription_duration_type'] == SwpmMembershipLevel::MONTHS) { return $item['subscription_period'] . " Month(s)"; } if ($item['subscription_duration_type'] == SwpmMembershipLevel::YEARS) { return $item['subscription_period'] . " Year(s)"; } } if ($column_name == 'role') { return ucfirst($item['role']); } return stripslashes($item[$column_name]); } function column_id($item) { $delete_swpmlevel_nonce = wp_create_nonce( 'nonce_delete_swpmlevel_admin_end' ); $actions = array( 'edit' => sprintf('Edit', $item['id']), 'delete' => sprintf('Delete', $item['id'],$delete_swpmlevel_nonce), ); return $item['id'] . $this->row_actions($actions); } function column_cb($item) { return sprintf( '', $item['id'] ); } function prepare_items() { global $wpdb; $this->process_bulk_action(); $query = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 "; if (isset($_POST['s'])){ $search_keyword = sanitize_text_field($_POST['s']); $search_keyword = esc_attr ($search_keyword); $query .= " AND alias LIKE '%" . $search_keyword . "%' "; } //Read and sanitize the sort inputs. $orderby = !empty($_GET["orderby"]) ? esc_sql($_GET["orderby"]) : 'id'; $order = !empty($_GET["order"]) ? esc_sql($_GET["order"]) : 'DESC'; $sortable_columns = $this->get_sortable_columns(); $orderby = SwpmUtils::sanitize_value_by_array($orderby, $sortable_columns); $order = SwpmUtils::sanitize_value_by_array($order, array('DESC' => '1', 'ASC' => '1')); if (!empty($orderby) && !empty($order)) { $query.=' ORDER BY ' . $orderby . ' ' . $order; } $totalitems = $wpdb->query($query); //Return the total number of affected rows $perpage = 50; $paged = !empty($_GET["paged"]) ? sanitize_text_field($_GET["paged"]) : ''; if (empty($paged) || !is_numeric($paged) || $paged <= 0) { $paged = 1; } $totalpages = ceil($totalitems / $perpage); if (!empty($paged) && !empty($perpage)) { $offset = ($paged - 1) * $perpage; $query.=' LIMIT ' . (int) $offset . ',' . (int) $perpage; } $this->set_pagination_args(array( "total_items" => $totalitems, "total_pages" => $totalpages, "per_page" => $perpage, )); $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); $this->items = $wpdb->get_results($query, ARRAY_A); } function no_items() { SwpmUtils::e('No membership levels found.'); } function process_form_request() { if (isset($_REQUEST['id'])) { //This is a level edit action $record_id = sanitize_text_field($_REQUEST['id']); if(!is_numeric($record_id)){ wp_die('Error! ID must be numeric.'); } return $this->edit($record_id); } //Level add action return $this->add(); } function add() { //Level add interface include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_add_level.php'); return false; } function edit($id) { global $wpdb; $query = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}swpm_membership_tbl WHERE id = %d", absint($id)); $membership = $wpdb->get_row($query, ARRAY_A); extract($membership, EXTR_SKIP); $email_activation = get_option('swpm_email_activation_lvl_'.$id); include_once(SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_edit_level.php'); return false; } function process_bulk_action() { //Detect when a bulk action is being triggered... global $wpdb; if ('bulk_delete' === $this->current_action()) { $records_to_delete = array_map( 'sanitize_text_field', $_REQUEST['ids'] ); if (empty($records_to_delete)) { echo '
Error! You need to select multiple records to perform a bulk action!
Selected records deleted successfully!
Selected record deleted successfully!