public function edit($id) { global $wpdb; $query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id = %d", $id); $level = $wpdb->get_row($query, ARRAY_A); $form = new BLevelForm($level); if ($form->is_valid()) { $wpdb->update($wpdb->prefix . "swpm_membership_tbl", $form->get_sanitized(), array('id' => $id)); //@todo meta table and collect all relevant info and pass as argument $custom = apply_filters('swpm_admin_edit_membership_level', array(), $id); $this->save_custom_fields($id, $custom); $message = array('succeeded' => true, 'message' => BUtils::_('Updated Successfully.')); BTransfer::get_instance()->set('status', $message); wp_redirect('admin.php?page=simple_wp_membership_levels'); return; } $message = array('succeeded' => false, 'message' => BUtils::_('Please correct the following:'), 'extra' => $form->get_errors()); BTransfer::get_instance()->set('status', $message); }
function prepare_items() { $submitted = filter_input(INPUT_POST, 'update_category_list'); if (!empty($submitted)) { $args = array('ids' => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY)); $filtered = filter_input_array(INPUT_POST, $args); $ids = $filtered['ids']; $args = array('ids_in_page' => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY)); $filtered = filter_input_array(INPUT_POST, $args); $ids_in_page = $filtered['ids_in_page']; $this->category->remove($ids_in_page, 'category')->apply($ids, 'category')->save(); $message = array('succeeded' => true, 'message' => BUtils::_('Updated! ')); BTransfer::get_instance()->set('status', $message); } $all_categories = array(); $all_cat_ids = get_categories(array('hide_empty' => '0')); $totalitems = count($all_cat_ids); $perpage = 100; $paged = !empty($_GET["paged"]) ? mysql_real_escape_string($_GET["paged"]) : ''; if (empty($paged) || !is_numeric($paged) || $paged <= 0) { $paged = 1; } $totalpages = ceil($totalitems / $perpage); $offset = 0; if (!empty($paged) && !empty($perpage)) { $offset = ($paged - 1) * $perpage; } for ($i = $offset; $i < (int) $offset + (int) $perpage && !empty($all_cat_ids[$i]); $i++) { $all_categories[] = $all_cat_ids[$i]; } $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 = $all_categories; }
public static function get_instance() { self::$_this = empty(self::$_this) ? new BTransfer() : self::$_this; self::$_this->message = get_option('swpm-messages'); return self::$_this; }
public function reset_password($email) { $email = sanitize_email($email); if (!is_email($email)) { $message = '<div class="swpm-reset-pw-error">' . BUtils::_("Email address not valid.") . '</div>'; $message = array('succeeded' => false, 'message' => $message); BTransfer::get_instance()->set('status', $message); return; } global $wpdb; $query = 'SELECT member_id,user_name,first_name, last_name FROM ' . $wpdb->prefix . 'swpm_members_tbl ' . ' WHERE email = %s'; $user = $wpdb->get_row($wpdb->prepare($query, $email)); if (empty($user)) { $message = '<div class="swpm-reset-pw-error">' . BUtils::_("No user not found with that email address.") . '</div>'; $message .= '<div class="swpm-reset-pw-error-email">' . BUtils::_("Email Address: ") . $email . '</div>'; $message = array('succeeded' => false, 'message' => $message); BTransfer::get_instance()->set('status', $message); return; } $settings = BSettings::get_instance(); $password = wp_generate_password(); $password_hash = BUtils::encrypt_password(trim($password)); //should use $saned??; $wpdb->update($wpdb->prefix . "swpm_members_tbl", array('password' => $password_hash), array('member_id' => $user->member_id)); // update wp user pass. BUtils::update_wp_user($user->user_name, array('plain_password' => $password)); $body = $settings->get_value('reset-mail-body'); $subject = $settings->get_value('reset-mail-subject'); $search = array('{user_name}', '{first_name}', '{last_name}', '{password}'); $replace = array($user->user_name, $user->first_name, $user->last_name, $password); $body = str_replace($search, $replace, $body); $from = $settings->get_value('email-from'); $headers = "From: " . $from . "\r\n"; wp_mail($email, $subject, $body, $headers); $message = '<div class="swpm-reset-pw-success">' . BUtils::_("New password has been sent to your email address.") . '</div>'; $message .= '<div class="swpm-reset-pw-success-email">' . BUtils::_("Email Address: ") . $email . '</div>'; $message = array('succeeded' => false, 'message' => $message); BTransfer::get_instance()->set('status', $message); }
public function edit($id) { global $wpdb; $query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id = %d", $id); $member = $wpdb->get_row($query, ARRAY_A); $email_address = $member['email']; $user_name = $member['user_name']; unset($member['member_id']); unset($member['user_name']); $form = new BForm($member); if ($form->is_valid()) { $member = $form->get_sanitized(); BUtils::update_wp_user($user_name, $member); unset($member['plain_password']); $wpdb->update($wpdb->prefix . "swpm_members_tbl", $member, array('member_id' => $id)); $message = array('succeeded' => true, 'message' => 'Updated Successfully.'); do_action('swpm_admin_edit_custom_fields', $member + array('member_id' => $id)); BTransfer::get_instance()->set('status', $message); $send_notification = filter_input(INPUT_POST, 'account_status_change'); if (!empty($send_notification)) { $settings = BSettings::get_instance(); $from_address = $settings->get_value('email-from'); $headers = 'From: ' . $from_address . "\r\n"; $subject = filter_input(INPUT_POST, 'notificationmailhead'); $body = filter_input(INPUT_POST, 'notificationmailbody'); $settings->set_value('account-change-email-body', $body)->set_value('account-change-email-subject', $subject)->save(); $member['login_link'] = $settings->get_value('login-page-url'); $values = array_values($member); $keys = array_map('swpm_enclose_var', array_keys($member)); $body = str_replace($keys, $values, $body); wp_mail($email_address, $subject, $body, $headers); } wp_redirect('admin.php?page=simple_wp_membership'); } $message = array('succeeded' => false, 'message' => BUtils::_('Please correct the following:'), 'extra' => $form->get_errors()); BTransfer::get_instance()->set('status', $message); }
public static function delete_wp_user($user_name) { $wp_user_id = username_exists($user_name); $ud = get_userdata($wp_user_id); if (!empty($ud) && (isset($ud->wp_capabilities['administrator']) || $ud->wp_user_level == 10)) { BTransfer::get_instance()->set('status', 'For consistency, we do not allow deleting any associated wordpress account with administrator role.<br/>' . 'Please delete from <a href="users.php">Users</a> menu.'); return; } if ($wp_user_id) { include_once ABSPATH . 'wp-admin/includes/user.php'; wp_delete_user($wp_user_id, 1); //assigns all related to this user to admin. } }