Cimy User Extra Fields - Version 1.5.3

Version Description

Download this release

Release Info

Developer Cimmo
Plugin Icon wp plugin Cimy User Extra Fields
Version 1.5.3
Comparing to
See all releases

Code changes from version 1.5.2 to 1.5.3

README_OFFICIAL.txt CHANGED
@@ -330,6 +330,44 @@ where $format is the date and time format, more tags details here:
330
  http://www.php.net/manual/en/function.strftime.php
331
 
332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
  [Function cimy_uef_sanitize_content]
334
  This function protects your blog from users trying to add JavaScript or alter your blog doing HTML injection in extra fields. It is very important that you do not remove that function.
335
  This function filters only some html tags and let other be used, the list of tags that are allowed is present under /wp-includes/kses.php search for $allowedtags array definition.
@@ -470,17 +508,29 @@ A: Probably you installed the first time WordPress on PHP4 and you experienced t
470
  To fix the problem you need to create another administrator user and change admin user to another role and then back to administrator.
471
 
472
 
473
- Q: When feature XYZ will be added?
474
-
475
- A: I don't know, remember that this is a 100% free project so answer is "When I have time and/or when someone help me with a donation".
476
-
477
-
478
  Q: I'm using your plug-in on WordPress MU per-blog installation, I'm registering users on one blog but they appear on the main blog too, why?
479
 
480
  A: Because WordPress MU is designed like that and I can't do anything about, however all extra fields and relative data are saved per-blog.
481
  Since I had already a long discussion with an user that didn't believe this, don't bother me to insist on this topic until you prove I'm wrong.
482
 
483
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
  Q: Can I help with a donation?
485
 
486
  A: Sure, visit the donation page or contact me via e-mail.
@@ -509,6 +559,11 @@ A lot of times I cannot reproduce the problem and I need more details, so if you
509
 
510
 
511
  CHANGELOG:
 
 
 
 
 
512
  v1.5.2 - 03/03/2010
513
  - Fixed profile page was not updating when setting 'Could not be empty' rule for picture, avatar or file fields (thanks to Erum Munir)
514
  - Fixed WordPress MU per-blog installation and wp-content in a custom location was giving PHP error after installing cimy_uef_mu_activation.php
330
  http://www.php.net/manual/en/function.strftime.php
331
 
332
 
333
+ [Function set_cimyFieldValue]
334
+ NOTE 1: the user should have permission to write the value: this mean if the function is used when no user is logged in will always fail.
335
+ NOTE 2: for checkbox fields use field_value=true/false to check/uncheck
336
+ NOTE 3: for radio fields use field_value equal to the label you want to select
337
+ NOTE 4: for dropdown fields use field_value equal to the item in the label you want to select
338
+ NOTE 5: for dropdown-multi fields use field_value equal to the items in the label you want to select separated by a comma: ','
339
+
340
+ USAGE:
341
+ $result = set_cimyFieldValue($user_id, $field_name, $field_value);
342
+
343
+ RETURNED VALUE:
344
+ An array is returned with all user ids where the change has been successful; empty array in case of error or the value is already in the DB.
345
+
346
+
347
+ CASE 1:
348
+ set an extra field value for a specific user
349
+
350
+ PARAMETERS: pass user_id as first parameter, field_name as second and field_value as third
351
+ RETURNED VALUE: the function will return an array containing USER_ID=1 if 'NEW_VALUE' has been written into 'MY_FIELD'
352
+
353
+ GENERIC:
354
+ $result = set_cimyFieldValue(<user_id>, <field_name>, <field_value>);
355
+ EXAMPLE:
356
+ $result = set_cimyFieldValue(1, 'MY_FIELD', 'NEW_VALUE');
357
+
358
+
359
+ CASE 2:
360
+ set an extra field value for all users
361
+
362
+ PARAMETERS: pass false as first parameter, field_name as second and field_value as third
363
+ RETURNED VALUE: the function will return an array containing all USER_IDs where 'NEW_VALUE' has been written into 'MY_FIELD'
364
+
365
+ GENERIC:
366
+ $result = set_cimyFieldValue(false, <field_name>, <field_value>);
367
+ EXAMPLE:
368
+ $result = set_cimyFieldValue(false, 'MY_FIELD', 'NEW_VALUE');
369
+
370
+
371
  [Function cimy_uef_sanitize_content]
372
  This function protects your blog from users trying to add JavaScript or alter your blog doing HTML injection in extra fields. It is very important that you do not remove that function.
373
  This function filters only some html tags and let other be used, the list of tags that are allowed is present under /wp-includes/kses.php search for $allowedtags array definition.
508
  To fix the problem you need to create another administrator user and change admin user to another role and then back to administrator.
509
 
510
 
 
 
 
 
 
511
  Q: I'm using your plug-in on WordPress MU per-blog installation, I'm registering users on one blog but they appear on the main blog too, why?
512
 
513
  A: Because WordPress MU is designed like that and I can't do anything about, however all extra fields and relative data are saved per-blog.
514
  Since I had already a long discussion with an user that didn't believe this, don't bother me to insist on this topic until you prove I'm wrong.
515
 
516
 
517
+ Q: I’m trying to use a regular expression in the rules, but the check does not work as expected, why?
518
+
519
+ A: Usually means your regex is wrong, please study how to properly build it: http://php.net/manual/en/function.preg-match.php
520
+
521
+
522
+ Q1: I do not see Extra Fields under the page user-new.php can you add there too?
523
+ Q2: How can I import new users with Extra Fields data into?
524
+
525
+ A: Unluckily due to a WordPress limitation I can’t add Extra Fields into user-new.php but you can quickly add all the users you want using my plugin:
526
+ Cimy User Manager – http://www.marcocimmino.net/cimy-wordpress-plugins/cimy-user-manager/
527
+
528
+
529
+ Q: When feature XYZ will be added?
530
+
531
+ A: I don't know, remember that this is a 100% free project so answer is "When I have time and/or when someone help me with a donation".
532
+
533
+
534
  Q: Can I help with a donation?
535
 
536
  A: Sure, visit the donation page or contact me via e-mail.
559
 
560
 
561
  CHANGELOG:
562
+ v1.5.3 - 09/04/2010
563
+ - Added set_cimyFieldValue function (thanks to Knark Planta for sponsoring)
564
+ - Fixed some PHP warnings
565
+ - Readme file updated
566
+
567
  v1.5.2 - 03/03/2010
568
  - Fixed profile page was not updating when setting 'Could not be empty' rule for picture, avatar or file fields (thanks to Erum Munir)
569
  - Fixed WordPress MU per-blog installation and wp-content in a custom location was giving PHP error after installing cimy_uef_mu_activation.php
cimy_uef_admin.php CHANGED
@@ -1338,7 +1338,7 @@ function cimy_admin_users_list_page() {
1338
  <div class="wrap">
1339
 
1340
  <?php
1341
- if (function_exists(screen_icon))
1342
  screen_icon("users");
1343
  ?>
1344
  <?php if ( $wp_user_search->is_search() ) : ?>
1338
  <div class="wrap">
1339
 
1340
  <?php
1341
+ if (function_exists("screen_icon"))
1342
  screen_icon("users");
1343
  ?>
1344
  <?php if ( $wp_user_search->is_search() ) : ?>
cimy_uef_db.php CHANGED
@@ -286,7 +286,7 @@ function cimy_manage_db($command) {
286
  // function to delete all files/subdirs in a path
287
  // taken from PHP unlink's documentation comment by torch - torchsdomain dot com @ 22-Nov-2006 09:27
288
  // modified by Marco Cimmino to delete correctly call recursion before so can also delete subdirs when empty
289
- if (!function_exists(cimy_rfr)) {
290
  function cimy_rfr($path, $match) {
291
  static $deld = 0, $dsize = 0;
292
 
286
  // function to delete all files/subdirs in a path
287
  // taken from PHP unlink's documentation comment by torch - torchsdomain dot com @ 22-Nov-2006 09:27
288
  // modified by Marco Cimmino to delete correctly call recursion before so can also delete subdirs when empty
289
+ if (!function_exists("cimy_rfr")) {
290
  function cimy_rfr($path, $match) {
291
  static $deld = 0, $dsize = 0;
292
 
cimy_uef_functions.php CHANGED
@@ -35,6 +35,98 @@ function get_cimyFields($wp_fields=false, $order_by_section=false) {
35
  return $extra_fields;
36
  }
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  function get_cimyFieldValue($user_id, $field_name, $field_value=false) {
39
  global $wpdb, $wpdb_data_table, $wpdb_fields_table;
40
 
@@ -189,12 +281,11 @@ function get_cimyFieldValue($user_id, $field_name, $field_value=false) {
189
  }
190
  else
191
  return NULL;
192
-
193
  $field_data = cimy_change_radio_labels($field_data);
194
-
195
  if (($field_name) && ($user_id))
196
  $field_data = $field_data[0]['VALUE'];
197
-
198
 
199
  return $field_data;
200
  }
35
  return $extra_fields;
36
  }
37
 
38
+ function set_cimyFieldValue($user_id, $field_name, $field_value) {
39
+ global $wpdb, $wpdb_data_table, $wpdb_fields_table;
40
+
41
+ $users = array();
42
+ $results = array();
43
+ $radio_ids = array();
44
+
45
+ if (empty($field_name))
46
+ return $results;
47
+
48
+ $field_name = $wpdb->escape(strtoupper($field_name));
49
+
50
+ $sql = "SELECT ID, TYPE, LABEL FROM $wpdb_fields_table WHERE NAME='$field_name'";
51
+ $efields = $wpdb->get_results($sql, ARRAY_A);
52
+
53
+ if ($efields == NULL)
54
+ return $results;
55
+
56
+ $type = $efields[0]['TYPE'];
57
+
58
+ if ($type == "radio") {
59
+ foreach ($efields as $ef) {
60
+ if ($ef['LABEL'] == $field_value) {
61
+ $field_value = "selected";
62
+ $field_id = $ef['ID'];
63
+ }
64
+ else
65
+ $radio_ids[] = $ef['ID'];
66
+ }
67
+
68
+ // if there are no radio fields with that label abort
69
+ if ($field_value != "selected")
70
+ return $results;
71
+ }
72
+ else if ($type == "checkbox") {
73
+ if (($field_value) || ($field_value == "YES"))
74
+ $field_value = "YES";
75
+ else
76
+ $field_value = "NO";
77
+
78
+ $field_id = $efields[0]['ID'];
79
+ }
80
+ else
81
+ $field_id = $efields[0]['ID'];
82
+
83
+ if ($user_id) {
84
+ $user_id = intval($user_id);
85
+ $user_info = get_userdata($user_id);
86
+ if (!$user_info)
87
+ return $results;
88
+ }
89
+ else {
90
+ $sql = "SELECT ID FROM $wpdb->users";
91
+ $users = $wpdb->get_results($sql, ARRAY_A);
92
+ }
93
+
94
+ if (empty($users))
95
+ $users[]["ID"] = $user_id;
96
+
97
+ $field_value = $wpdb->escape($field_value);
98
+
99
+ foreach ($users as $user) {
100
+ if (!current_user_can('edit_user', $user["ID"]))
101
+ continue;
102
+
103
+ $sql = "SELECT ID FROM $wpdb_data_table WHERE FIELD_ID=$field_id AND USER_ID=".$user["ID"];
104
+ $exist = $wpdb->get_var($sql);
105
+
106
+ if ($exist == NULL)
107
+ $sql = "INSERT INTO $wpdb_data_table SET USER_ID=".$user["ID"].", VALUE='$field_value', FIELD_ID=$field_id";
108
+ else
109
+ $sql = "UPDATE $wpdb_data_table SET VALUE='$field_value' WHERE FIELD_ID=$field_id AND USER_ID=".$user["ID"];
110
+
111
+
112
+ $add_field_result = $wpdb->query($sql);
113
+
114
+ if ($add_field_result > 0)
115
+ $results[]["USER_ID"] = $user["ID"];
116
+
117
+ if ($type == "radio") {
118
+ if (!empty($radio_ids)) {
119
+ foreach ($radio_ids as $r_id) {
120
+ $sql2 = "UPDATE $wpdb_data_table SET VALUE='' WHERE FIELD_ID=$r_id AND USER_ID=".$user["ID"];
121
+ $result_sql2 = $wpdb->query($sql2);
122
+ }
123
+ }
124
+ }
125
+ }
126
+
127
+ return $results;
128
+ }
129
+
130
  function get_cimyFieldValue($user_id, $field_name, $field_value=false) {
131
  global $wpdb, $wpdb_data_table, $wpdb_fields_table;
132
 
281
  }
282
  else
283
  return NULL;
284
+
285
  $field_data = cimy_change_radio_labels($field_data);
286
+
287
  if (($field_name) && ($user_id))
288
  $field_data = $field_data[0]['VALUE'];
 
289
 
290
  return $field_data;
291
  }
cimy_uef_options.php CHANGED
@@ -404,7 +404,7 @@ function cimy_show_options($results, $embedded) {
404
 
405
  <div class="wrap" id="options">
406
  <?php
407
- if (function_exists(screen_icon))
408
  screen_icon("options-general");
409
  ?>
410
  <h2><?php _e("Options");
404
 
405
  <div class="wrap" id="options">
406
  <?php
407
+ if (function_exists("screen_icon"))
408
  screen_icon("options-general");
409
  ?>
410
  <h2><?php _e("Options");
cimy_user_extra_fields.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Cimy User Extra Fields
4
  Plugin URI: http://www.marcocimmino.net/cimy-wordpress-plugins/cimy-user-extra-fields/
5
  Plugin Description: Add some useful fields to registration and user's info
6
- Version: 1.5.2
7
  Author: Marco Cimmino
8
  Author URI: mailto:cimmino.marco@gmail.com
9
  */
@@ -192,7 +192,7 @@ require_once($cuef_plugin_dir.'/cimy_uef_options.php');
192
  require_once($cuef_plugin_dir.'/cimy_uef_admin.php');
193
 
194
  $cimy_uef_name = "Cimy User Extra Fields";
195
- $cimy_uef_version = "1.5.2";
196
  $cimy_uef_url = "http://www.marcocimmino.net/cimy-wordpress-plugins/cimy-user-extra-fields/";
197
 
198
  $start_cimy_uef_comment = "<!--\n";
@@ -808,7 +808,7 @@ function cimy_manage_upload($input_name, $user_login, $rules, $old_file=false, $
808
  // should be stay AFTER DELETIONS
809
  if ((isset($rules['equal_to'])) && ($type != "file")) {
810
  if ($maxside = intval($rules['equal_to'])) {
811
- if (!function_exists(image_resize))
812
  require_once(ABSPATH . 'wp-includes/media.php');
813
 
814
  if (!function_exists(wp_load_image))
3
  Plugin Name: Cimy User Extra Fields
4
  Plugin URI: http://www.marcocimmino.net/cimy-wordpress-plugins/cimy-user-extra-fields/
5
  Plugin Description: Add some useful fields to registration and user's info
6
+ Version: 1.5.3
7
  Author: Marco Cimmino
8
  Author URI: mailto:cimmino.marco@gmail.com
9
  */
192
  require_once($cuef_plugin_dir.'/cimy_uef_admin.php');
193
 
194
  $cimy_uef_name = "Cimy User Extra Fields";
195
+ $cimy_uef_version = "1.5.3";
196
  $cimy_uef_url = "http://www.marcocimmino.net/cimy-wordpress-plugins/cimy-user-extra-fields/";
197
 
198
  $start_cimy_uef_comment = "<!--\n";
808
  // should be stay AFTER DELETIONS
809
  if ((isset($rules['equal_to'])) && ($type != "file")) {
810
  if ($maxside = intval($rules['equal_to'])) {
811
+ if (!function_exists("image_resize"))
812
  require_once(ABSPATH . 'wp-includes/media.php');
813
 
814
  if (!function_exists(wp_load_image))
readme.txt CHANGED
@@ -5,7 +5,7 @@ Website link: http://www.marcocimmino.net/cimy-wordpress-plugins/cimy-user-extra
5
  Tags: cimy, admin, registration, profile, extra fields, avatar, gravatar
6
  Requires at least: 2.6
7
  Tested up to: 2.9
8
- Stable tag: 1.5.2
9
 
10
  Add some useful fields to registration and user's info
11
 
5
  Tags: cimy, admin, registration, profile, extra fields, avatar, gravatar
6
  Requires at least: 2.6
7
  Tested up to: 2.9
8
+ Stable tag: 1.5.3
9
 
10
  Add some useful fields to registration and user's info
11