| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if( file_exists( dirname(__FILE__) . '/base.php') ) |
| 8 |
require_once('base.php'); |
| 9 |
class Profile_admin extends PieReg_Base |
| 10 |
{ |
| 11 |
var $field; |
| 12 |
var $user_id; |
| 13 |
var $slug; |
| 14 |
var $type; |
| 15 |
var $name; |
| 16 |
var $id; |
| 17 |
var $data; |
| 18 |
|
| 19 |
function __construct($form_id = "default") |
| 20 |
{ |
| 21 |
parent::__construct(); |
| 22 |
$this->data = $this->getCurrentFields($form_id); |
| 23 |
$this->default_fields = FALSE; |
| 24 |
add_action("init", array($this,"get_user_registered_form")); |
| 25 |
add_action( 'user_edit_form_tag', array($this,"piereg_wp_admin_form_tag") ); |
| 26 |
} |
| 27 |
function get_user_registered_form(){ |
| 28 |
if(is_user_logged_in()){ |
| 29 |
$form_id = get_user_meta(get_current_user_id(),"user_registered_form_id",true); |
| 30 |
if( is_numeric($form_id) && !empty($form_id) ) |
| 31 |
$this->data = $this->getCurrentFields($form_id); |
| 32 |
} |
| 33 |
} |
| 34 |
function addTextField($disabled) |
| 35 |
{ |
| 36 |
$val = get_user_meta($this->user_id, $this->slug, true); #get_usermeta deprecated |
| 37 |
if(is_array($val)) |
| 38 |
{ |
| 39 |
$val = implode( ",", $val ); |
| 40 |
} |
| 41 |
echo '<input'.esc_attr($disabled).' id="' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '" class="' . esc_attr($this->field['css']) . '" placeholder="' . esc_attr($this->field['placeholder']) . '" type="text" value="' . esc_attr($val) . '" />'; |
| 42 |
} |
| 43 |
|
| 44 |
function addTextArea($disabled) |
| 45 |
{ |
| 46 |
$val = get_user_meta($this->user_id, $this->slug, true); #get_usermeta deprecated |
| 47 |
if(is_array($val)) |
| 48 |
{ |
| 49 |
$val = implode( ",", $val ); |
| 50 |
} |
| 51 |
echo '<textarea'.esc_attr($disabled).' id="' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '" rows="' . esc_attr($this->field['rows']) . '" cols="' . esc_attr($this->field['cols']) . '" class="' . esc_attr($this->field['css']) . '" placeholder="' . esc_attr($this->field['placeholder']) . '">' . esc_textarea($val) . '</textarea>'; |
| 52 |
} |
| 53 |
|
| 54 |
function addDropdown($disabled) |
| 55 |
{ |
| 56 |
$sel_options = get_user_meta($this->user_id, $this->slug, true); #get_usermeta deprecated |
| 57 |
$multiple = ""; |
| 58 |
if ($this->type == "multiselect") { |
| 59 |
$multiple = 'multiple'; |
| 60 |
$this->slug .= "[]"; |
| 61 |
echo '<select' . esc_attr($disabled) . ' ' . esc_attr($multiple) . ' id="' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '" class="' . esc_attr($this->field['css']) . '" style="min-width:200px;" >'; |
| 62 |
if($this->field['list_type']=="country") |
| 63 |
{ |
| 64 |
$countries = get_option("pie_countries"); |
| 65 |
echo wp_kses($this->createDropdown($countries,$sel_options), $this->piereg_forms_get_allowed_tags()); |
| 66 |
} |
| 67 |
else if($this->field['list_type']=="us_states") |
| 68 |
{ |
| 69 |
$us_states = get_option("pie_us_states"); |
| 70 |
echo wp_kses($this->createDropdown($us_states,$sel_options), $this->piereg_forms_get_allowed_tags()); |
| 71 |
} |
| 72 |
else if($this->field['list_type']=="can_states") |
| 73 |
{ |
| 74 |
$can_states = get_option("pie_can_states"); |
| 75 |
echo wp_kses($this->createDropdown($can_states,$sel_options), $this->piereg_forms_get_allowed_tags()); |
| 76 |
} |
| 77 |
else if (sizeof($this->field['value']) > 0) { |
| 78 |
for ($a = 0; $a < sizeof($this->field['value']); $a++) { |
| 79 |
$selected = ''; |
| 80 |
if(isset($this->field['value'][$a]) && !empty($this->field['value'][$a])) |
| 81 |
{ |
| 82 |
$sel_options = (isset($sel_options[0]) && is_array($sel_options[0])) ? $sel_options[0] : $sel_options; |
| 83 |
if ( !empty($sel_options) && in_array($this->field['value'][$a], $sel_options)){ |
| 84 |
$selected = 'selected'; |
| 85 |
} |
| 86 |
} |
| 87 |
if ($this->field['value'][$a] != "" || $this->field['display'][$a] != "") |
| 88 |
echo '<option ' . esc_attr($selected) . ' value="' . esc_attr($this->field['value'][$a]) . '">' . esc_html($this->field['display'][$a]) . '</option>'; |
| 89 |
} |
| 90 |
} |
| 91 |
echo '</select>'; |
| 92 |
}elseif ($this->type == "dropdown"){ |
| 93 |
$sel_options = (isset($sel_options[0]) && is_array($sel_options[0])) ? $sel_options[0] : $sel_options; |
| 94 |
$this->slug .= "[]"; |
| 95 |
echo '<select' . esc_attr($disabled) . ' id="' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '" class="' . esc_attr($this->field['css']) . '" style="min-width:100px;" >'; |
| 96 |
if($this->field['list_type']=="country") |
| 97 |
{ |
| 98 |
$countries = get_option("pie_countries"); |
| 99 |
echo wp_kses($this->createDropdown($countries,$sel_options), $this->piereg_forms_get_allowed_tags()); |
| 100 |
} |
| 101 |
else if($this->field['list_type']=="us_states") |
| 102 |
{ |
| 103 |
$us_states = get_option("pie_us_states"); |
| 104 |
echo wp_kses($this->createDropdown($us_states,$sel_options), $this->piereg_forms_get_allowed_tags()); |
| 105 |
} |
| 106 |
else if($this->field['list_type']=="can_states") |
| 107 |
{ |
| 108 |
$can_states = get_option("pie_can_states"); |
| 109 |
echo wp_kses($this->createDropdown($can_states,$sel_options), $this->piereg_forms_get_allowed_tags()); |
| 110 |
} |
| 111 |
else if (sizeof($this->field['value']) > 0) { |
| 112 |
|
| 113 |
for ($a = 0; $a < sizeof($this->field['value']); $a++) { |
| 114 |
$selected = ''; |
| 115 |
$sel_options = (isset($sel_options[0]) && is_array($sel_options[0])) ? $sel_options[0] : $sel_options; |
| 116 |
if ( is_array($sel_options) ) |
| 117 |
{ |
| 118 |
if ( in_array($this->field['value'][$a], $sel_options) ) { |
| 119 |
$selected = 'selected'; |
| 120 |
} |
| 121 |
} |
| 122 |
if ($this->field['value'][$a] != "" || $this->field['display'][$a] != "") |
| 123 |
echo '<option ' . esc_attr($selected) . ' value="' . esc_attr($this->field['value'][$a]) . '">' . esc_html($this->field['display'][$a]) . '</option>'; |
| 124 |
} |
| 125 |
} |
| 126 |
echo '</select>'; |
| 127 |
|
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
function addNumberField($disabled) |
| 132 |
{ |
| 133 |
$val = get_user_meta($this->user_id, $this->slug, true); #get_usermeta deprecated |
| 134 |
if(is_array($val)) |
| 135 |
{ |
| 136 |
$val = implode( ",", $val ); |
| 137 |
} |
| 138 |
echo '<input' . esc_attr($disabled) .' id="' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '" class="' . esc_attr($this->field['css']) . '" placeholder="' . esc_attr($this->field['placeholder']) . '" min="' . esc_attr($this->field['min']) . '" max="' . esc_attr($this->field['max']) . '" type="number" value="' . esc_attr($val) . '" />'; |
| 139 |
} |
| 140 |
|
| 141 |
function addCheckRadio($disabled) |
| 142 |
{ |
| 143 |
if (sizeof($this->field['value']) > 0) { |
| 144 |
$val = get_user_meta($this->user_id, $this->slug, true); #get_usermeta deprecated |
| 145 |
for ($a = 0; $a < sizeof($this->field['value']); $a++) { |
| 146 |
$checked = ''; |
| 147 |
$val = (isset($val[0]) && is_array($val[0])) ? $val[0] : $val; |
| 148 |
if (is_array($val) && in_array($this->field['value'][$a], $val)) { |
| 149 |
$checked = 'checked="checked"'; |
| 150 |
} |
| 151 |
echo '<span style="margin-left:5px;">'.esc_html($this->field['display'][$a]).'</span>'; |
| 152 |
echo '<input' . esc_attr($disabled) . ' style="margin-left:5px;" value="' . esc_attr($this->field['value'][$a]) . '" ' . esc_attr($checked) . ' type="' . esc_attr($this->type) . '" name="' . esc_attr($this->slug) . '[]" class="' . esc_attr($this->field['css']) . '" >'; |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
function addHTML() |
| 158 |
{ |
| 159 |
echo wp_kses(html_entity_decode($this->field['html']), $this->piereg_forms_get_allowed_tags()); |
| 160 |
} |
| 161 |
|
| 162 |
function addUpload($disabled) |
| 163 |
{ |
| 164 |
$val = get_user_meta($this->user_id, $this->slug, true); #get_usermeta deprecated |
| 165 |
|
| 166 |
if(is_array($val)) |
| 167 |
{ |
| 168 |
$val = !empty($val) ? $val[0] : ''; |
| 169 |
|
| 170 |
$temp_dir = $this->piereg_get_uploaded_dir($this->user_id, $this->slug); |
| 171 |
if(!file_exists($temp_dir."/".basename($val))){ |
| 172 |
$val = ''; |
| 173 |
} |
| 174 |
} |
| 175 |
echo '<div class="fieldset"><input'.esc_attr($disabled).' name="' . esc_attr($this->slug) . '" type="file" value="'.esc_attr($val) .'">'; |
| 176 |
echo (trim($val) != "")? '<br /><div class="file-wrapper"><a href="'.esc_url($val).'" target="_blank">'.esc_html(basename($val)).'</a><br /><a class="file-remove" href="javascript:;">Remove</a></div><input type="hidden" name="'.esc_attr($this->slug).'_removed" value="0" /></div>' : ""; |
| 177 |
} |
| 178 |
|
| 179 |
function addProfilePic($disabled) |
| 180 |
{ |
| 181 |
$val = get_user_meta($this->user_id , $this->slug, true); #get_usermeta deprecated |
| 182 |
|
| 183 |
if(is_array($val)) |
| 184 |
{ |
| 185 |
$val = implode( ",", $val ); |
| 186 |
} |
| 187 |
echo '<input'.esc_attr($disabled).' id="'.esc_attr($this->id).'" name="'.esc_attr($this->slug).'" type="file" class=" validate[funcCall[checkExtensions],ext[gif|jpeg|jpg|png|bmp]]" />'; |
| 188 |
echo '<input id="'.esc_attr($this->id).'" name="'.esc_attr($this->slug).'_hidden" value="'.esc_attr($val).'" type="hidden" />'; |
| 189 |
|
| 190 |
$ext = (trim(basename($val)))? $val." Not Found" : "Profile Pictuer Not Found"; |
| 191 |
$imgPath = (trim($val) != "")? $val : plugins_url("assets/images/userImage.png",dirname(__FILE__)); |
| 192 |
echo '<br /><img src="'.esc_url($imgPath).'" style="max-width:150px;" alt="'.esc_attr(__('User Profile Picture',"pie-register")).'" />'; |
| 193 |
} |
| 194 |
|
| 195 |
function addAddress($disabled) |
| 196 |
{ |
| 197 |
$address = get_user_meta($this->user_id, $this->slug, true); #get_usermeta deprecated |
| 198 |
echo '<div class="address"> |
| 199 |
<input'.esc_attr($disabled).' type="text" name="' . esc_attr($this->slug) . '[address]" id="' . esc_attr($this->id) . '" value="' . ((isset($address['address']))?esc_attr($address['address']):"") . '" > |
| 200 |
<label>'.esc_html__("Street Address","pie-register").'</label> |
| 201 |
</div>'; |
| 202 |
if (empty($this->field['hide_address2'])) { |
| 203 |
echo '<div class="address"> |
| 204 |
<input'.esc_attr($disabled).' type="text" name="' . esc_attr($this->slug) . '[address2]" id="address2_' . esc_attr($this->id) . '" value="' . ((isset($address['address2']))?esc_attr($address['address2']):"") . '" > |
| 205 |
<label>'.esc_html__("Address Line 2","pie-register").'</label> |
| 206 |
</div>'; |
| 207 |
} |
| 208 |
echo '<div class="address"> |
| 209 |
<div class="address2"> |
| 210 |
<input'.esc_attr($disabled).' type="text" name="' . esc_attr($this->slug) . '[city]" id="city_' . esc_attr($this->id) . '" value="' . ((isset($address['city']))?esc_attr($address['city']):"") . '"> |
| 211 |
<label>'.esc_html__("City","pie-register").'</label> |
| 212 |
</div>'; |
| 213 |
if (empty($this->field['hide_state'])) { |
| 214 |
if ($this->field['address_type'] == "International") { |
| 215 |
echo '<div class="address2" > |
| 216 |
<input'.esc_attr($disabled).' type="text" name="' . esc_attr($this->slug) . '[state]" id="state_' . esc_attr($this->id) . '" value="' . ((isset($address['state']))?esc_attr($address['state']):"") . '"> |
| 217 |
<label>'.esc_html__("State / Province / Region","pie-register").'</label> |
| 218 |
</div>'; |
| 219 |
} else if ($this->field['address_type'] == "United States") { |
| 220 |
$us_states = get_option("pie_us_states"); |
| 221 |
$options = $this->createDropdown($us_states, ((isset($address['state']))?$address['state']:"")); |
| 222 |
echo '<div class="address2" > |
| 223 |
<select'.esc_attr($disabled).' id="state_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[state]"> |
| 224 |
' . wp_kses($options, $this->piereg_forms_get_allowed_tags()) . ' |
| 225 |
</select> |
| 226 |
<label>'.esc_html__("State","pie-register").'</label> |
| 227 |
</div>'; |
| 228 |
} else if ($this->field['address_type'] == "Canada") { |
| 229 |
$can_states = get_option("pie_can_states"); |
| 230 |
$options = $this->createDropdown($can_states, ((isset($address['state']))?$address['state']:"")); |
| 231 |
echo '<div class="address2"> |
| 232 |
<select'.esc_attr($disabled).' id="state_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[state]"> |
| 233 |
' . wp_kses($options, $this->piereg_forms_get_allowed_tags()) . ' |
| 234 |
</select> |
| 235 |
<label>'.esc_html__("Province","pie-register").'</label> |
| 236 |
</div>'; |
| 237 |
} |
| 238 |
} |
| 239 |
echo '</div>'; |
| 240 |
echo '<div class="address">'; |
| 241 |
echo ' <div class="address2"> |
| 242 |
<input'.esc_attr($disabled).' id="zip_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[zip]" type="text" value="' . ((isset($address['zip']))?esc_attr($address['zip']):"") . '" > |
| 243 |
<label>'.esc_html__("Zip / Postal Code","pie-register").'</label> |
| 244 |
</div>'; |
| 245 |
if ($this->field['address_type'] == "International") { |
| 246 |
$countries = get_option("pie_countries"); |
| 247 |
$options = $this->createDropdown($countries, ((isset($address['country']))?$address['country']:"")); |
| 248 |
echo '<div class="address2" > |
| 249 |
<select'.esc_attr($disabled).' id="country_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[country]" > |
| 250 |
<option value="">'.esc_html(__("Select Country","pie-register")).'</option> |
| 251 |
' . wp_kses($options, $this->piereg_forms_get_allowed_tags()) . ' |
| 252 |
</select> |
| 253 |
<label>'.esc_html__("Country","pie-register").'</label> |
| 254 |
</div>'; |
| 255 |
} |
| 256 |
echo '</div>'; |
| 257 |
} |
| 258 |
|
| 259 |
function addPhone($disabled) |
| 260 |
{ |
| 261 |
$val = get_user_meta($this->user_id, $this->slug, true); #get_usermeta deprecated |
| 262 |
if(is_array($val)) |
| 263 |
{ |
| 264 |
$val = implode( ",", $val ); |
| 265 |
} |
| 266 |
echo '<input'.esc_attr($disabled).' id="' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '" class="input_fields" placeholder="' . (isset($this->field['placeholder']) ? esc_attr($this->field['placeholder']) : "") . '" type="text" value="' . esc_attr($val) . '" />'; |
| 267 |
} |
| 268 |
|
| 269 |
function addInvitation($disabled) |
| 270 |
{ |
| 271 |
$val = get_user_meta($this->user_id, "invite_code", true); #get_usermeta deprecated |
| 272 |
if(is_array($val)) |
| 273 |
{ |
| 274 |
$val = implode( ",", $val ); |
| 275 |
} |
| 276 |
echo '<input'.esc_attr($disabled).' id="' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '" class="input_fields" placeholder="' . (isset($this->field['placeholder']) ? esc_attr($this->field['placeholder']) : "") . '" type="text" disabled="disabled" style="width:25em;" value="' . esc_attr($val) . '" />'; |
| 277 |
} |
| 278 |
|
| 279 |
function addTime($disabled) |
| 280 |
{ |
| 281 |
$time = get_user_meta($this->user_id, $this->slug, true); #get_usermeta deprecated |
| 282 |
echo '<input' . esc_attr($disabled) . ' size="2" maxlength="2" id="hh_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[hh]" type="text" value="' . ((isset($time['hh']))?esc_attr($time['hh']):"") . '"> : <input' . esc_attr($disabled) . ' size="2" maxlength="2" id="mm_' . esc_attr($this->id) . '" type="text" name="' . esc_attr($this->slug) . '[mm]" value="' . ((isset($time['mm']))?esc_attr($time['mm']):"") . '">'; |
| 283 |
|
| 284 |
if ($this->field['time_type'] == "12") { |
| 285 |
$time_format = ((isset($time['time_format']))?$time['time_format']:""); |
| 286 |
echo '<select' . esc_attr($disabled) . ' name="' . esc_attr($this->slug) . '[time_format]" > |
| 287 |
<option ' . (($time_format == "am") ? 'selected' : "") . ' value="am">'.esc_html(__("AM","pie-register")).'</option> |
| 288 |
<option ' . (($time_format == "pm") ? 'selected' : "") . ' value="pm">'.esc_html(__("PM","pie-register")).'</option> |
| 289 |
</select>'; |
| 290 |
} |
| 291 |
echo '</div>'; |
| 292 |
} |
| 293 |
|
| 294 |
function addDate($disabled) |
| 295 |
{ |
| 296 |
$date = get_user_meta($this->user_id, $this->slug, true); #get_usermeta deprecated |
| 297 |
if(!$date) |
| 298 |
{ |
| 299 |
if(!is_array($date)) $date = array(); |
| 300 |
$date['date']['mm'] = ""; |
| 301 |
$date['date']['dd'] = ""; |
| 302 |
$date['date']['yy'] = ""; |
| 303 |
} |
| 304 |
if ($this->field['date_type'] == "datefield") { |
| 305 |
if ( isset($date['date'][0]) && !is_array($date['date'][0]) ) |
| 306 |
{ |
| 307 |
$date['date']['mm'] = ""; |
| 308 |
$date['date']['dd'] = ""; |
| 309 |
$date['date']['yy'] = ""; |
| 310 |
} |
| 311 |
if ($this->field['date_format'] == "mm/dd/yy") { |
| 312 |
echo '<div class="piereg_time date_format_field"> |
| 313 |
<div class="time_fields"> |
| 314 |
<input'.esc_attr($disabled).' id="mm_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[date][mm]" maxlength="2" type="text" value="' . esc_attr($date['date']['mm']) . '" data-type="date"> |
| 315 |
<label>'.esc_html_e("MM","pie-register").'</label> |
| 316 |
</div> |
| 317 |
<div class="time_fields"> |
| 318 |
<input'.esc_attr($disabled).' id="dd_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[date][dd]" maxlength="2" type="text" value="' . esc_attr($date['date']['dd']) . '" data-type="date"> |
| 319 |
<label>'.esc_html_e("DD","pie-register").'</label> |
| 320 |
</div> |
| 321 |
<div class="time_fields"> |
| 322 |
<input'.esc_attr($disabled).' id="yy_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[date][yy]" maxlength="4" type="text" value="' . esc_attr($date['date']['yy']) . '" data-type="date"> |
| 323 |
<label>'.esc_html_e("yy","pie-register").'</label> |
| 324 |
</div> |
| 325 |
</div>'; |
| 326 |
} else if ($this->field['date_format'] == "yy/mm/dd" || $this->field['date_format'] == "yy.mm.dd") { |
| 327 |
echo '<div class="piereg_time date_format_field"> |
| 328 |
<div class="time_fields"> |
| 329 |
<input'.esc_attr($disabled).' id="yy_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[date][yy]" maxlength="4" type="text" value="' . esc_attr($date['date']['yy']) . '" data-type="date"> |
| 330 |
<label>'.esc_html_e("yy","pie-register").'</label> |
| 331 |
</div> |
| 332 |
<div class="time_fields"> |
| 333 |
<input'.esc_attr($disabled).' id="mm_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[date][mm]" maxlength="2" type="text" value="' . esc_attr($date['date']['mm']) . '" data-type="date"> |
| 334 |
<label>'.esc_html_e("MM","pie-register").'</label> |
| 335 |
</div> |
| 336 |
<div class="time_fields"> |
| 337 |
<input'.esc_attr($disabled).' id="dd_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[date][dd]" maxlength="2" type="text" value="' . esc_attr($date['date']['dd']) . '" data-type="date"> |
| 338 |
<label>'.esc_html_e("DD","pie-register").'</label> |
| 339 |
</div> |
| 340 |
</div>'; |
| 341 |
} else { |
| 342 |
echo '<div class="piereg_time date_format_field"> |
| 343 |
<div class="time_fields"> |
| 344 |
<input'.esc_attr($disabled).' id="dd_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[date][dd]" maxlength="2" type="text" value="' . esc_attr($date['date']['dd']) . '" data-type="date"> |
| 345 |
<label>'.esc_html_e("DD","pie-register").'</label> |
| 346 |
</div> |
| 347 |
<div class="time_fields"> |
| 348 |
<input'.esc_attr($disabled).' id="yy_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[date][yy]" maxlength="4" type="text" value="' . esc_attr($date['date']['yy']) . '" data-type="date"> |
| 349 |
<label>'.esc_html_e("yy","pie-register").'</label> |
| 350 |
</div> |
| 351 |
<div class="time_fields"> |
| 352 |
<input'.esc_attr($disabled).' id="mm_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[date][mm]" maxlength="2" type="text" value="' . esc_attr($date['date']['mm']) . '" data-type="date"> |
| 353 |
<label>'.esc_html_e("MM","pie-register").'</label> |
| 354 |
</div> |
| 355 |
</div>'; |
| 356 |
} |
| 357 |
} |
| 358 |
else if ($this->field['date_type'] == "datepicker") { |
| 359 |
$returned_date = ( isset($date['date'][0]) ) ? $date['date'][0] : ""; |
| 360 |
echo '<div class="piereg_time date_format_field"> |
| 361 |
<input'.esc_attr($disabled).' id="' . esc_attr($this->id) . '" readonly class="date_start" name="' . esc_attr($this->slug) . '[date][]" value="' . esc_attr($returned_date) . '" type="text" ></div>'; |
| 362 |
} else if ($this->field['date_type'] == "datedropdown") { |
| 363 |
if ( isset($date['date'][0]) && !is_array($date['date'][0]) ) |
| 364 |
{ |
| 365 |
$date['date']['mm'] = ""; |
| 366 |
$date['date']['dd'] = ""; |
| 367 |
$date['date']['yy'] = ""; |
| 368 |
} |
| 369 |
echo '<div class="piereg_time date_format_field"> |
| 370 |
<select'.esc_attr($disabled).' id="mm_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[date][mm]" data-type="date"> |
| 371 |
<option value="">'.esc_html(__("Month","pie-register")).'</option>'; |
| 372 |
for ($a = 1; $a <= 12; $a++) { |
| 373 |
$sel = ''; |
| 374 |
if ((int) $a == (int) $date['date']['mm']) { |
| 375 |
$sel = 'selected'; |
| 376 |
} |
| 377 |
echo '<option ' . esc_attr($sel) . ' value="' . esc_attr($a) . '">' . esc_html( sprintf( "%02s", $a ) ) . '</option>'; |
| 378 |
} |
| 379 |
echo '</select> |
| 380 |
<select'.esc_attr($disabled).' id="dd_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[date][dd]" data-type="date"> |
| 381 |
<option value="">'.esc_html(__("Day","pie-register")).'</option>'; |
| 382 |
for ($a = 1; $a <= 31; $a++) { |
| 383 |
$sel = ''; |
| 384 |
if ((int) $a == (int) $date['date']['dd']) { |
| 385 |
$sel = 'selected'; |
| 386 |
} |
| 387 |
echo '<option ' . esc_attr($sel) . ' value="' . esc_attr($a) . '">' . esc_html(__sprintf("%02s", $a ) ) . '</option>'; |
| 388 |
} |
| 389 |
echo '</select> |
| 390 |
<select'.esc_attr($disabled).' id="yy_' . esc_attr($this->id) . '" name="' . esc_attr($this->slug) . '[date][yy]" data-type="date"> |
| 391 |
<option value="">'.esc_html(__("Year","pie-register")).'</option>'; |
| 392 |
for ($a = 2099; $a >= 1900; $a--) { |
| 393 |
$sel = ''; |
| 394 |
if ((int) $a == (int) $date['date']['yy']) { |
| 395 |
$sel = 'selected'; |
| 396 |
} |
| 397 |
echo '<option ' . esc_attr($sel) . ' value="' . esc_attr($a) . '">' . esc_html($a) . '</option>'; |
| 398 |
} |
| 399 |
echo '</select> |
| 400 |
</div>'; |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
function addList($disabled) |
| 405 |
{ |
| 406 |
$list = get_user_meta($this->user_id, $this->slug, true); #get_usermeta deprecated |
| 407 |
if(!is_array($list)) |
| 408 |
$list = array(); |
| 409 |
$width = 90 / $this->field['cols']; |
| 410 |
for($a = 1 ,$c=0; $a <= $this->field['rows'] ; $a++,$c++) |
| 411 |
{ |
| 412 |
echo '<div style="max-width:55%;">'; |
| 413 |
for($b = 1,$d=0 ; $b <= $this->field['cols'] ;$b++,$d++) |
| 414 |
{ |
| 415 |
echo '<input'.esc_attr($disabled).' value="'.((isset($list[$c][$d]))?esc_attr($list[$c][$d]):"").'" style="width:'.esc_attr($width).'%;margin-right:2px;" type="text" name="'.esc_attr($this->slug.'['.$c.'][]').'" class="input_fields"> '; |
| 416 |
} |
| 417 |
echo '</div>'; |
| 418 |
} |
| 419 |
} |
| 420 |
function addTerms($disabled){ |
| 421 |
$disabled = ' disabled'; |
| 422 |
$val = get_user_meta($this->user_id, $this->slug, true); #get_usermeta deprecated |
| 423 |
|
| 424 |
echo '<input'.esc_attr($disabled).' '. checked($val == '1', true, false) .' id="' . esc_attr($this->id) . '" type="checkbox" value="'.esc_attr($val).'" >'; |
| 425 |
|
| 426 |
$page_id = $this->field['cont']; |
| 427 |
$page_url = get_the_permalink($page_id); |
| 428 |
|
| 429 |
// translators: %s is replaced by the URL link to view the terms page |
| 430 |
echo wp_kses(apply_filters('piereg_terms_field_text',sprintf( __('Click <a target="_blank" href="%s">here</a> to view.','pie-register'),$page_url)), $this->piereg_forms_get_allowed_tags()); |
| 431 |
} |
| 432 |
function createFieldName($text) |
| 433 |
{ |
| 434 |
return "pie_".$this->getMetaKey($text); |
| 435 |
} |
| 436 |
|
| 437 |
function createFieldID() |
| 438 |
{ |
| 439 |
$key_id = (isset($this->field['id'])) ? $this->field['id'] : ""; |
| 440 |
return "field_" . $key_id; |
| 441 |
} |
| 442 |
|
| 443 |
function addLabel() |
| 444 |
{ |
| 445 |
return '<label for="' . esc_attr($this->id) . '">' . esc_html($this->field['label']) . '</label>'; |
| 446 |
} |
| 447 |
|
| 448 |
function printFields() |
| 449 |
{ |
| 450 |
$update = get_option(OPTION_PIE_REGISTER); |
| 451 |
$disabled = ""; |
| 452 |
|
| 453 |
if( !current_user_can( 'edit_users' ) ) { |
| 454 |
$disabled = ' disabled'; |
| 455 |
} |
| 456 |
|
| 457 |
switch ($this->type): |
| 458 |
case 'text': |
| 459 |
$this->addTextField($disabled); |
| 460 |
break; |
| 461 |
case 'textarea': |
| 462 |
$this->addTextArea($disabled); |
| 463 |
break; |
| 464 |
case 'dropdown': |
| 465 |
case 'multiselect': |
| 466 |
$this->addDropdown($disabled); |
| 467 |
break; |
| 468 |
case 'number': |
| 469 |
$this->addNumberField($disabled); |
| 470 |
break; |
| 471 |
case 'radio': |
| 472 |
case 'checkbox': |
| 473 |
$this->addCheckRadio($disabled); |
| 474 |
break; |
| 475 |
case 'html': |
| 476 |
$this->addHTML(); |
| 477 |
break; |
| 478 |
case 'time': |
| 479 |
$this->addTime($disabled); |
| 480 |
break; |
| 481 |
case 'upload': |
| 482 |
$this->addUpload($disabled); |
| 483 |
break; |
| 484 |
case 'profile_pic': |
| 485 |
$this->addProfilePic($disabled); |
| 486 |
break; |
| 487 |
case 'address': |
| 488 |
$this->addAddress($disabled); |
| 489 |
break; |
| 490 |
//Pie-register-woocommerce Addon |
| 491 |
case 'wc_billing_address': |
| 492 |
if ($this->woocommerce_and_piereg_wc_addon_active) |
| 493 |
{ |
| 494 |
echo wp_kses(apply_filters("pieregister_print_woocommerce_billing_address_admin_profile", $disabled), $this->piereg_forms_get_allowed_tags()); |
| 495 |
} |
| 496 |
break; |
| 497 |
case 'wc_shipping_address': |
| 498 |
if ($this->woocommerce_and_piereg_wc_addon_active) |
| 499 |
{ |
| 500 |
echo wp_kses(apply_filters("pieregister_print_woocommerce_shipping_address_admin_profile", $disabled), $this->piereg_forms_get_allowed_tags()); |
| 501 |
} |
| 502 |
break; |
| 503 |
case 'phone': |
| 504 |
/* |
| 505 |
* Just Work 2 way login |
| 506 |
*/ |
| 507 |
case 'two_way_login_phone': |
| 508 |
$this->addPhone($disabled); |
| 509 |
break; |
| 510 |
|
| 511 |
case 'invitation': |
| 512 |
$this->addInvitation($disabled); |
| 513 |
break; |
| 514 |
|
| 515 |
case 'date': |
| 516 |
$this->addDate($disabled); |
| 517 |
break; |
| 518 |
case 'list': |
| 519 |
$this->addList($disabled); |
| 520 |
break; |
| 521 |
case 'terms': |
| 522 |
$this->addTerms($disabled); |
| 523 |
break; |
| 524 |
endswitch; |
| 525 |
} |
| 526 |
function edit_user_profile($user) |
| 527 |
{ |
| 528 |
$form_id = "default"; |
| 529 |
if(isset($_GET['user_id'])){ |
| 530 |
$form_id = get_user_meta((intval(sanitize_key($_GET['user_id']))),"user_registered_form_id",true); |
| 531 |
$user_id = intval(sanitize_key($_GET['user_id'])); |
| 532 |
}elseif(is_admin()){ |
| 533 |
$form_id = get_user_meta((intval($user->ID)),"user_registered_form_id",true); |
| 534 |
$user_id = intval($user->ID); |
| 535 |
}else{ |
| 536 |
return; |
| 537 |
} |
| 538 |
|
| 539 |
$form_id = ((!empty($form_id)) ? $form_id : "default"); |
| 540 |
if( $form_id == 'default' ) { |
| 541 |
$form_free_id = $this->regFormForFreeVers(); |
| 542 |
update_user_meta($user_id, 'user_registered_form_id', $form_free_id); |
| 543 |
$form_id = $form_free_id; |
| 544 |
} |
| 545 |
|
| 546 |
$this->data = $this->getCurrentFields($form_id); |
| 547 |
|
| 548 |
/** |
| 549 |
* IF USER ASSIGNED FORM DELETED, THEN ASSIGN DEFAULT FORM |
| 550 |
* since v3.6 |
| 551 |
*/ |
| 552 |
if(!is_array($this->data) || sizeof($this->data) == 0) { |
| 553 |
$this->data = $this->getCurrentFields($this->regFormForFreeVers()); |
| 554 |
update_user_meta($user_id, 'user_registered_form_id', $form_free_id); |
| 555 |
} |
| 556 |
|
| 557 |
if (sizeof($this->data) > 0 && is_array($this->data)) |
| 558 |
{ |
| 559 |
$this->user_id = $user->ID; |
| 560 |
echo "<h3>". esc_html__('Pie Register Registration Fields','pie-register')."</h3>"; |
| 561 |
echo '<table class="form-table">'; |
| 562 |
|
| 563 |
foreach ($this->data as $this->field) |
| 564 |
{ |
| 565 |
$key_id = (isset($this->field['id'])) ? $this->field['id'] : ""; |
| 566 |
$this->slug = $this->createFieldName($this->field['type']."_".$key_id); |
| 567 |
$this->type = $this->field['type']; |
| 568 |
$this->id = $this->createFieldID(); |
| 569 |
if((isset($this->field['show_in_profile']) and $this->field['show_in_profile'] == 0 ) && !is_admin()) |
| 570 |
continue; |
| 571 |
/* |
| 572 |
* Just work 2way login |
| 573 |
*/ |
| 574 |
if($this->type == "two_way_login_phone") |
| 575 |
{ |
| 576 |
$this->slug = "piereg_two_way_login_phone"; |
| 577 |
} |
| 578 |
//When to add label |
| 579 |
switch($this->type) : |
| 580 |
case 'two_way_login_phone': |
| 581 |
include_once( $this->admin_path . 'includes/plugin.php' ); |
| 582 |
$twilio_option = get_option("pie_register_twilio"); |
| 583 |
$plugin_status = get_option('piereg_api_manager_addon_Twilio_activated'); |
| 584 |
if( is_plugin_active("pie-register-twilio/pie-register-twilio.php") && isset($twilio_option["enable_twilio"]) && $twilio_option["enable_twilio"] == 1 && $plugin_status == "Activated" ){ |
| 585 |
echo '<tr><td>'.wp_kses_post($this->addLabel()).'</td><td>'; |
| 586 |
echo wp_kses($this->printFields(), $this->piereg_forms_get_allowed_tags()).'</td></tr>'; |
| 587 |
} |
| 588 |
break; |
| 589 |
case 'time': |
| 590 |
case 'text' : |
| 591 |
case 'textarea': |
| 592 |
case 'dropdown': |
| 593 |
case 'multiselect': |
| 594 |
case 'number': |
| 595 |
case 'radio': |
| 596 |
case 'checkbox': |
| 597 |
case 'upload': |
| 598 |
case 'profile_pic': |
| 599 |
case 'address': |
| 600 |
case 'phone': |
| 601 |
/* |
| 602 |
* Just Work 2 way login |
| 603 |
*/ |
| 604 |
|
| 605 |
case 'invitation': |
| 606 |
case 'date': |
| 607 |
case 'list': |
| 608 |
case "default" && $this->default_fields: |
| 609 |
echo '<tr><th>'.wp_kses_post($this->addLabel()).'</th><td>'; |
| 610 |
echo wp_kses($this->printFields(),$this->piereg_forms_get_allowed_tags()).'</td></tr>'; |
| 611 |
break; |
| 612 |
case "terms": |
| 613 |
echo '<tr><th>'.wp_kses_post($this->addLabel()).'</th><td>'; |
| 614 |
echo wp_kses($this->printFields(),$this->piereg_forms_get_allowed_tags()).'</td></tr>'; |
| 615 |
break; |
| 616 |
endswitch; |
| 617 |
} |
| 618 |
echo '</table>'; |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
function updateMyProfile($user_id) |
| 623 |
{ |
| 624 |
if ( current_user_can( 'edit_users' ) ) // only admin can update profile from WP Admin Profile Page |
| 625 |
{ |
| 626 |
$this->updateProfile($user_id); |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
function validate_user_profile($errors, $update, $user) |
| 631 |
{ |
| 632 |
/* |
| 633 |
* Sanitizing post data |
| 634 |
*/ |
| 635 |
$this->pie_post_array = $this->piereg_sanitize_post_data_escape( ( (isset($_POST) && !empty($_POST))?$_POST : array() ) ); |
| 636 |
foreach ($this->data as $this->field) { |
| 637 |
$this->slug = $this->createFieldName($this->field['label']); |
| 638 |
$this->type = $this->type; |
| 639 |
$this->id = $this->createFieldID(); |
| 640 |
|
| 641 |
/* |
| 642 |
* Just Work 2way login |
| 643 |
*/ |
| 644 |
if($this->field['type'] == "two_way_login_phone") |
| 645 |
{ |
| 646 |
$this->slug = "piereg_two_way_login_phone"; |
| 647 |
} |
| 648 |
|
| 649 |
$field_name = $this->pie_post_array[$this->slug]; |
| 650 |
$required = $this->field['required']; |
| 651 |
$rule = $this->field['validation_rule']; |
| 652 |
$validation_message = (!empty($this->field['validation_message']) ? $this->field['validation_message'] : $this->field['label'] . " is required."); |
| 653 |
if ((!isset($field_name) || empty($field_name)) && $required) { |
| 654 |
$errors->add($this->slug, '<strong>'.esc_html(ucwords(__('error','pie-register'))).'</strong>: ' . esc_html($validation_message)); |
| 655 |
} else if ($rule == "number") { |
| 656 |
if (!is_numeric($field_name)) { |
| 657 |
$errors->add( $this->slug , '<strong>'.ucwords(__('error','pie-register')).'</strong>: '.$this->field['label'] .apply_filters("piereg_field_must_contain_only_numbers",__('Field must only contain numbers.','pie-register' ))); |
| 658 |
} |
| 659 |
} else if ($rule == "alphanumeric") { |
| 660 |
if (!preg_match("/^([a-z 0-9])+$/i", $field_name)) { |
| 661 |
$errors->add( $this->slug , '<strong>'.ucwords(__('error','pie-register')).'</strong>: '.$this->field['label'] .apply_filters("piereg_field_may_only_contain_alpha_numeric_characters",__(' Field must only contain alpha-numeric characters.','pie-register' ))); |
| 662 |
} |
| 663 |
} else if ($rule == "email") { |
| 664 |
if (!filter_var($field_name, FILTER_VALIDATE_EMAIL)) { |
| 665 |
$errors->add( $this->slug , '<strong>'.ucwords(__('error','pie-register')).'</strong>: '.$this->field['label'].apply_filters("piereg_field_must_contain_a_valid_email_address",__(' Field must contain a valid email address.','pie-register' ))); |
| 666 |
} |
| 667 |
} else if ($rule == "website") { |
| 668 |
if (!filter_var($field_name, FILTER_VALIDATE_URL)) { |
| 669 |
$errors->add( $this->slug , '<strong>'.ucwords(__('error','pie-register')).'</strong>: '.$this->field['label'] .apply_filters("piereg_must_be_a_valid_URL",__(' Must be a valid URL.','pie-register' ))); |
| 670 |
} |
| 671 |
} |
| 672 |
} |
| 673 |
if (sizeof($errors->errors) == 0) { |
| 674 |
$this->updateProfile($user->ID); |
| 675 |
} |
| 676 |
return $errors; |
| 677 |
} |
| 678 |
|
| 679 |
function updateProfile($user_id) |
| 680 |
{ |
| 681 |
$form_id = get_user_meta($user_id,"user_registered_form_id",true); |
| 682 |
$this->data = $this->getCurrentFields($form_id); |
| 683 |
|
| 684 |
if( empty($this->pie_post_array) ) { |
| 685 |
$this->pie_post_array = $this->piereg_sanitize_post_data_escape( ( (isset($_POST) && !empty($_POST))?$_POST : array() ) ); |
| 686 |
} |
| 687 |
|
| 688 |
global $errors; |
| 689 |
$errors = new WP_Error(); |
| 690 |
|
| 691 |
if( isset($this->pie_post_array['pie_form_assign']) && !empty($this->pie_post_array['pie_form_assign']) && ($this->pie_post_array['pie_form_assign'] !== $form_id) ) |
| 692 |
{ |
| 693 |
update_user_meta($user_id,"user_registered_form_id", $this->pie_post_array['pie_form_assign']); |
| 694 |
} |
| 695 |
|
| 696 |
foreach ($this->data as $this->field){ |
| 697 |
//When to add label |
| 698 |
if(!isset($this->field['id'])) continue; |
| 699 |
$slug = $this->createFieldName($this->field['type']."_".$this->field['id']); |
| 700 |
if( $this->field['type'] == "upload" ) |
| 701 |
{ |
| 702 |
if(isset($this->pie_post_array[$slug.'_removed']) && $this->pie_post_array[$slug.'_removed'] == "1") |
| 703 |
{ |
| 704 |
$this->pie_remove_upload( $user_id, $this->field, $slug ); |
| 705 |
} |
| 706 |
} |
| 707 |
switch($this->field['type']) : |
| 708 |
case 'time': |
| 709 |
if($this->pie_post_array[$slug]['time_format']) |
| 710 |
{ |
| 711 |
$this->pie_post_array[$slug]['hh'] = intval($this->pie_post_array[$slug]['hh']); |
| 712 |
if($this->pie_post_array[$slug]['hh'] > 12) |
| 713 |
$this->pie_post_array[$slug]['hh'] = "12"; |
| 714 |
$this->pie_post_array[$slug]['mm'] = intval($this->pie_post_array[$slug]['mm']); |
| 715 |
if($this->pie_post_array[$slug]['mm'] > 59) |
| 716 |
$this->pie_post_array[$slug]['mm'] = "59"; |
| 717 |
$field_name = $this->pie_post_array[$slug]; |
| 718 |
update_user_meta($user_id, $slug, $this->pie_post_array[$slug]); |
| 719 |
}else{ |
| 720 |
$this->pie_post_array[$slug]['hh'] = intval($this->pie_post_array[$slug]['hh']); |
| 721 |
if($this->pie_post_array[$slug]['hh'] > 23) |
| 722 |
$this->pie_post_array[$slug]['hh'] = "23"; |
| 723 |
$this->pie_post_array[$slug]['mm'] = intval($this->pie_post_array[$slug]['mm']); |
| 724 |
if($this->pie_post_array[$slug]['mm'] > 59) |
| 725 |
$this->pie_post_array[$slug]['mm'] = "59"; |
| 726 |
$field_name = $this->pie_post_array[$slug]; |
| 727 |
update_user_meta($user_id, $slug, $this->pie_post_array[$slug]); |
| 728 |
} |
| 729 |
break; |
| 730 |
case 'upload': |
| 731 |
$this->pie_upload_files($user_id,$this->field,$slug); |
| 732 |
break; |
| 733 |
case 'profile_pic': |
| 734 |
$this->pie_profile_pictures_upload($user_id,$this->field,$slug); |
| 735 |
break; |
| 736 |
case 'text' : |
| 737 |
case 'textarea': |
| 738 |
case 'dropdown': |
| 739 |
case 'multiselect': |
| 740 |
case 'number': |
| 741 |
case 'radio': |
| 742 |
case 'checkbox': |
| 743 |
// case 'html': |
| 744 |
// case 'invitation': |
| 745 |
case 'address': |
| 746 |
case 'phone': |
| 747 |
case 'date': |
| 748 |
case 'list': |
| 749 |
$field_value = $this->pie_post_array[$slug]; |
| 750 |
update_user_meta($user_id,$slug, $field_value); |
| 751 |
break; |
| 752 |
/* |
| 753 |
* Just work 2way login phone |
| 754 |
*/ |
| 755 |
case "two_way_login_phone": |
| 756 |
$slug = "piereg_two_way_login_phone"; |
| 757 |
$field_value = $this->pie_post_array[$slug]; |
| 758 |
update_user_meta($user_id,$slug, $field_value); |
| 759 |
break; |
| 760 |
endswitch; |
| 761 |
} |
| 762 |
} |
| 763 |
function pie_profile_pictures_upload($user_id,$field,$field_slug,$form_id=0){ |
| 764 |
global $errors; |
| 765 |
$errors = new WP_Error(); |
| 766 |
if($_FILES[$field_slug]['name'] != ''){ |
| 767 |
/** |
| 768 |
* UPLOAD PROFILE PICTURE |
| 769 |
*/ |
| 770 |
$result = $this->piereg_validate_files(sanitize_file_name($_FILES[$field_slug]['name']),array("gif","jpeg","jpg","png","bmp")); |
| 771 |
if($result) |
| 772 |
{ |
| 773 |
$temp = explode(".", $_FILES[$field_slug]["name"]); |
| 774 |
$extension = end($temp); |
| 775 |
$upload_dir = wp_upload_dir(); |
| 776 |
$temp_dir = realpath($upload_dir['basedir'])."/piereg_users_files/".$user_id; |
| 777 |
wp_mkdir_p($temp_dir); |
| 778 |
$temp_file_name = sanitize_file_name("profile_pic_".crc32($user_id."_".$extension."_".time()).".".$extension); |
| 779 |
$temp_file_url = $upload_dir['baseurl']."/piereg_users_files/".$user_id."/".$temp_file_name; |
| 780 |
$required = $field['required']; |
| 781 |
$wp_filesystem = $this->pie_get_filesystem(); |
| 782 |
if(!$wp_filesystem->move($_FILES[$field_slug]['tmp_name'],$temp_dir."/".$temp_file_name) && $required){ |
| 783 |
$errors->add( $field_slug , '<strong>'.ucwords(__('error','pie-register')).'</strong>: '.apply_filters("piereg_Fail_to_upload_profile_picture",__('Failed to upload the profile picture.','pie-register' ))); |
| 784 |
}else{ |
| 785 |
update_user_meta($user_id,$field_slug, $temp_file_url); |
| 786 |
} |
| 787 |
}else{ |
| 788 |
$errors->add( $field_slug , '<strong>'.ucwords(__('error','pie-register')).'</strong>: '.apply_filters("piereg_invalid_profile_picture",__('Invalid profile picture','pie-register' ))); |
| 789 |
} |
| 790 |
} |
| 791 |
} |
| 792 |
function pie_remove_upload($user_id,$field,$field_slug) { |
| 793 |
$upload_dir = wp_upload_dir(); |
| 794 |
$temp_dir = realpath($upload_dir['basedir'])."/piereg_users_files/".$user_id; |
| 795 |
$file = get_user_meta($user_id,$field_slug, true); |
| 796 |
if ( is_array($file) ) |
| 797 |
{ |
| 798 |
$file = $file[0]; |
| 799 |
} |
| 800 |
if( !empty($file ) ){ |
| 801 |
$wp_filesystem = $this->pie_get_filesystem(); |
| 802 |
if( $wp_filesystem->exists($temp_dir."/".basename( $file )) ){ |
| 803 |
$wp_filesystem->delete( $temp_dir."/".basename( $file ) ); |
| 804 |
} else if ( $wp_filesystem->exists($temp_dir."/".$field_slug."/".basename( $file )) ) { |
| 805 |
$this->delete_directory( realpath($temp_dir."/".$field_slug)); |
| 806 |
} |
| 807 |
} |
| 808 |
delete_user_meta($user_id,$field_slug); |
| 809 |
$this->pie_success = 1; |
| 810 |
} |
| 811 |
|
| 812 |
function pie_upload_files($user_id,$field,$field_slug,$form_id=0) |
| 813 |
{ |
| 814 |
global $errors; |
| 815 |
$errors = new WP_Error(); |
| 816 |
$required = $field['required']; |
| 817 |
if($_FILES[$field_slug]['name'] != ''){ |
| 818 |
if($field['file_types'] != ""){ |
| 819 |
$filter_string = stripcslashes($field['file_types']); |
| 820 |
$filter_array = explode(",",$filter_string); |
| 821 |
$result = $this->piereg_validate_files(sanitize_file_name($_FILES[$field_slug]['name']),$filter_array); |
| 822 |
if($result){ |
| 823 |
$temp = explode(".", sanitize_file_name($_FILES[$field_slug]["name"])); |
| 824 |
$extension = end($temp); |
| 825 |
$upload_dir = wp_upload_dir(); |
| 826 |
$temp_dir = realpath($upload_dir['basedir'])."/piereg_users_files/".$user_id."/".$field_slug.""; |
| 827 |
wp_mkdir_p($temp_dir); |
| 828 |
$temp_file_name = sanitize_file_name("file_".crc32($user_id."_".$extension."_".time()).".".$extension); |
| 829 |
$temp_file_url = $upload_dir['baseurl']."/piereg_users_files/".$user_id."/".$field_slug."/".$temp_file_name; |
| 830 |
|
| 831 |
// Allowed Mime Types in WordPress |
| 832 |
$allowed_mime_types = get_allowed_mime_types(); |
| 833 |
$valid_mime_type = wp_check_filetype($temp_file_name,$allowed_mime_types); |
| 834 |
|
| 835 |
// Validate file extension type |
| 836 |
$validate_file_ext_type = wp_check_filetype_and_ext( $temp_file_url, $temp_file_name ); |
| 837 |
|
| 838 |
if ( ( $valid_mime_type['type'] !== false ) && ( $validate_file_ext_type['ext'] !== false ) && ( $validate_file_ext_type['type'] !== false) ) |
| 839 |
{ |
| 840 |
$wp_filesystem = $this->pie_get_filesystem(); |
| 841 |
if(!$wp_filesystem->move($_FILES[$field_slug]['tmp_name'],$temp_dir."/".$temp_file_name) && $required){ |
| 842 |
$errors->add( $field_slug , '<strong>'.ucwords(__('error','pie-register')).'</strong>: '.apply_filters("piereg_Fail_to_upload_profile_picture",__('Failed to upload the profile picture.','pie-register' ))); |
| 843 |
}else{ |
| 844 |
update_user_meta($user_id,$field_slug, $temp_file_url); |
| 845 |
} |
| 846 |
} |
| 847 |
else |
| 848 |
{ |
| 849 |
$errors->add( $field_slug , '<strong>'.ucwords(__('error','pie-register')).'</strong>: '.apply_filters("piereg_fail_to_upload_profile_picture",__('File Type Is Not Permitted','pie-register' ))); |
| 850 |
} |
| 851 |
} |
| 852 |
else{ |
| 853 |
$errors->add( $field_slug , '<strong>'.ucwords(__('error','pie-register')).'</strong>: '.apply_filters("piereg_Invlid_upload_file",__('Invalid upload file.','pie-register' ))); |
| 854 |
} |
| 855 |
}else{ |
| 856 |
$temp = explode(".", sanitize_file_name($_FILES[$field_slug]["name"])); |
| 857 |
$extension = end($temp); |
| 858 |
$upload_dir = wp_upload_dir(); |
| 859 |
$temp_dir = realpath($upload_dir['basedir'])."/piereg_users_files/".$user_id."/".$field_slug.""; |
| 860 |
wp_mkdir_p($temp_dir); |
| 861 |
$temp_file_name = sanitize_file_name("file_".crc32($user_id."_".$extension."_".time()).".".$extension); |
| 862 |
$temp_file_url = $upload_dir['baseurl']."/piereg_users_files/".$user_id."/".$field_slug."/".$temp_file_name; |
| 863 |
|
| 864 |
// Allowed Mime Types in WordPress |
| 865 |
$allowed_mime_types = get_allowed_mime_types(); |
| 866 |
$valid_mime_type = wp_check_filetype($temp_file_name,$allowed_mime_types); |
| 867 |
|
| 868 |
// Validate file extension type |
| 869 |
$validate_file_ext_type = wp_check_filetype_and_ext( $temp_file_url, $temp_file_name ); |
| 870 |
|
| 871 |
if ( ( $valid_mime_type['type'] !== false ) && ( $validate_file_ext_type['ext'] !== false ) && ( $validate_file_ext_type['type'] !== false) ) |
| 872 |
{ |
| 873 |
$wp_filesystem = $this->pie_get_filesystem(); |
| 874 |
if(!$wp_filesystem->move($_FILES[$field_slug]['tmp_name'],$temp_dir."/".$temp_file_name) && $required){ |
| 875 |
$errors->add( $field_slug , '<strong>'.ucwords(__('error','pie-register')).'</strong>: '.apply_filters("piereg_Fail_to_upload_profile_picture",__('Failed to upload the profile picture.','pie-register' ))); |
| 876 |
}else{ |
| 877 |
update_user_meta($user_id,$field_slug, $temp_file_url); |
| 878 |
} |
| 879 |
} |
| 880 |
else |
| 881 |
{ |
| 882 |
$errors->add( $field_slug , '<strong>'.ucwords(__('error','pie-register')).'</strong>: '.apply_filters("piereg_fail_to_upload_profile_picture",__('File Type Is Not Permitted','pie-register' ))); |
| 883 |
} |
| 884 |
} |
| 885 |
} |
| 886 |
} |
| 887 |
function delete_directory($dirname) { |
| 888 |
$wp_filesystem = $this->pie_get_filesystem(); |
| 889 |
if ($wp_filesystem->is_dir($dirname)) { |
| 890 |
return $wp_filesystem->rmdir($dirname, true); |
| 891 |
} |
| 892 |
return false; |
| 893 |
} |
| 894 |
private function pie_get_filesystem() { |
| 895 |
global $wp_filesystem; |
| 896 |
if ( empty( $wp_filesystem ) ) { |
| 897 |
require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
| 898 |
WP_Filesystem(); |
| 899 |
} |
| 900 |
return $wp_filesystem; |
| 901 |
} |
| 902 |
function piereg_wp_admin_form_tag(){ |
| 903 |
echo ' enctype="multipart/form-data" '; |
| 904 |
} |
| 905 |
} |
| 906 |
?> |