PluginProbe
Welcart e-Commerce / 2.12.1
Welcart e-Commerce v2.12.1
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / includes / member / wel-member-class.php

wel-member-class.php in Welcart e-Commerce 2.12.1, at includes/member/wel-member-class.php

198 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Welcart member class
4 *
5 * @package Welcart
6 */
7
8 namespace Welcart;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * Member class
16 *
17 * The Welcart item class handles individual member data.
18 *
19 * @since 2.2.2
20 */
21 class MemberData {
22
23 /**
24 * ID for this object.
25 *
26 * @since 2.2.2
27 * @var int
28 */
29 protected $id = 0;
30
31 /**
32 * Core data for this object. Name value pairs (name + default value).
33 *
34 * @since 2.2.2
35 * @var array
36 */
37 protected $data = array();
38
39 /**
40 * Meta data for this object. Name value pairs (name + default value).
41 *
42 * @since 2.2.2
43 * @var array
44 */
45 protected $meta = array();
46
47 /**
48 * Extra data for this object. Name value pairs (name + default value).
49 *
50 * @since 2.2.2
51 * @var array
52 */
53 protected $extra_data = array();
54
55 /**
56 * Get the Member if ID is passed, otherwise data is false.
57 * This class should not be instantiated.
58 * The wc_get_member() function should be used instead.
59 *
60 * @param int $member_id ID of the member.
61 */
62 public function __construct( $member_id = 0 ) {
63 if ( is_numeric( $member_id ) && $member_id > 0 ) {
64 $this->set_id( $member_id );
65 } else {
66 $this->set_id( 0 );
67 }
68
69 $this->set_data( $this->id );
70 }
71
72 /**
73 * Set ID.
74 *
75 * @param int $id ID.
76 */
77 public function set_id( $id ) {
78 $this->id = absint( $id );
79 }
80
81 /**
82 * Set data.
83 *
84 * @since 2.2.2
85 * @param int $member_id Memner id.
86 */
87 public function set_data( $member_id ) {
88 global $wpdb;
89
90 if ( 0 === $member_id ) {
91 return false;
92 }
93
94 // core data.
95 $member_cache_key = 'wel_member_data_' . $member_id;
96 $_data = wp_cache_get( $member_cache_key );
97 if ( false === $_data ) {
98 $table = usces_get_tablename( 'usces_member' );
99 $_data = $wpdb->get_row(
100 $wpdb->prepare( "SELECT * FROM {$table} WHERE ID = %d", $member_id )
101 );
102 if ( null !== $_data ) {
103 wp_cache_set( $member_cache_key, $_data );
104 }
105 }
106
107 if ( null === $_data ) {
108 return false;
109 }
110
111 $this->data = array(
112 'ID' => $_data->ID,
113 'registered' => $_data->mem_registered,
114 'mailaddress' => $_data->mem_email,
115 'point' => $_data->mem_point,
116 'name1' => $_data->mem_name1,
117 'name2' => $_data->mem_name2,
118 'name3' => $_data->mem_name3,
119 'name4' => $_data->mem_name4,
120 'zipcode' => $_data->mem_zip,
121 'address1' => $_data->mem_address1,
122 'address2' => $_data->mem_address2,
123 'address3' => $_data->mem_address3,
124 'tel' => $_data->mem_tel,
125 'fax' => $_data->mem_fax,
126 'pref' => $_data->mem_pref,
127 'status' => $_data->mem_status,
128 );
129
130 // meta data.
131 $member_meta_cache_key = 'wel_member_meta_' . $member_id;
132
133 $_meta = wp_cache_get( $member_meta_cache_key );
134 if ( false === $_meta ) {
135 $table = usces_get_tablename( 'usces_member_meta' );
136 $query = $wpdb->prepare( "SELECT meta_key, meta_value FROM {$table} WHERE member_id = %d", $member_id );
137 $_meta = $wpdb->get_results( $query );
138 if ( null !== $_meta ) {
139 wp_cache_set( $member_meta_cache_key, $_meta );
140 }
141 }
142
143 foreach ( $_meta as $meta ) {
144 $this->meta[ $meta->meta_key ] = maybe_unserialize( $meta->meta_value );
145 }
146
147 $this->data = array_merge( $this->data, $this->meta );
148 }
149
150 /**
151 * Returns all data for this object.
152 *
153 * @since 2.2.2
154 * @return array
155 */
156 public function get_data() {
157 if ( ! isset( $this->data['ID'] ) ) {
158 return false;
159 } else {
160 return array_merge( $this->data, $this->extra_data );
161 }
162 }
163
164 /**
165 * Returns member's ID by email.
166 *
167 * @since 2.2.2
168 * @param string $email Member's email address.
169 * @return int ID
170 */
171 public function get_id_by_email( $email ) {
172 global $wpdb;
173
174 $cache_key = 'wel_member_id_by_email_' . $email;
175
176 $id = wp_cache_get( $cache_key );
177 if ( false === $id ) {
178 $table = usces_get_tablename( 'usces_member' );
179 $id = $wpdb->get_var(
180 $wpdb->prepare(
181 "SELECT `ID` FROM {$table} WHERE mem_email = %s",
182 $email
183 )
184 );
185 if ( null !== $id ) {
186 wp_cache_set( $cache_key, $id );
187 }
188 }
189
190 if ( null === $id ) {
191 return false;
192 } else {
193 return $id;
194 }
195 }
196
197 }
198