<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][12869] trunk/src/bp-xprofile: Prepare the xProfile component to handle the WordPress field types</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/12869">12869</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/12869","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>imath</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-03-22 19:45:24 +0000 (Mon, 22 Mar 2021)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Prepare the xProfile component to handle the WordPress field types
- Add a cache group to cache usermeta IDs by user IDs to avoid requesting information more than necessary when it hasn't been updated.
- Edit the Profile field sanitization filter `bp_xprofile_escape_field_data` so that WordPress fields are escaped the way WordPress does.
- Add the two new Field types `wp-biography` & `wp-textbox` to the available ones. See `bp_xprofile_get_field_types()`.
- Introduce the `bp_xprofile_get_field_type()` function to get the fied type of a field thanks to its ID.
- Introduce a new filter `bp_xprofile_set_field_data_pre_save`. This filter returns `false` by default. You can use it to avoid using the Profile data DB table to save a field value by returning a WP_Error object or true. This filter is used by the WordPress field types to avoid duplicating the corresponding usermeta values into the Profile data DB table.
- Introduce the `bp_xprofile_get_wp_user_keys()` function to inform about the supported WordPress fields (`first_name`, `last_name`, `user_url`, `description` and potential WP contact methods).
- Edit the `BP_XProfile_ProfileData` methods to fetch field data so that they now try to fetch data within the usermeta table if the xProfile field has a WordPress field type.
- Deprecate the `BP_XProfile_ProfileData::get_value_byfieldname()` as it's no more used into BP Core code.
- Edit the function used to output the fields into the WP Admin/Extended profile screen so that WordPress fields are ignored as they can be updated from the WP Admin regular profile.
Props DJPaul, Offereins, needle, netweb, vapvarun
See <a href="http://buddypress.trac.wordpress.org/ticket/7162">#7162</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpxprofilebpxprofilecachephp">trunk/src/bp-xprofile/bp-xprofile-cache.php</a></li>
<li><a href="#trunksrcbpxprofilebpxprofilefiltersphp">trunk/src/bp-xprofile/bp-xprofile-filters.php</a></li>
<li><a href="#trunksrcbpxprofilebpxprofilefunctionsphp">trunk/src/bp-xprofile/bp-xprofile-functions.php</a></li>
<li><a href="#trunksrcbpxprofileclassesclassbpxprofilecomponentphp">trunk/src/bp-xprofile/classes/class-bp-xprofile-component.php</a></li>
<li><a href="#trunksrcbpxprofileclassesclassbpxprofileprofiledataphp">trunk/src/bp-xprofile/classes/class-bp-xprofile-profiledata.php</a></li>
<li><a href="#trunksrcbpxprofileclassesclassbpxprofileuseradminphp">trunk/src/bp-xprofile/classes/class-bp-xprofile-user-admin.php</a></li>
<li><a href="#trunksrcbpxprofilescreenseditphp">trunk/src/bp-xprofile/screens/edit.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpxprofilebpxprofilecachephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/bp-xprofile-cache.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/bp-xprofile-cache.php 2021-03-21 14:17:21 UTC (rev 12868)
+++ trunk/src/bp-xprofile/bp-xprofile-cache.php 2021-03-22 19:45:24 UTC (rev 12869)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -302,3 +302,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // List actions to clear super cached pages on, if super cache is installed.
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'xprofile_updated_profile', 'bp_core_clear_cache' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Resets the User Metadata ids cache.
+ *
+ * @since 8.0.0
+ *
+ * @param integer $user_id The user ID.
+ */
+function bp_xprofile_reset_user_mid_cache( $user_id ) {
+ wp_cache_delete( $user_id, 'bp_user_mid' );
+}
+add_action( 'profile_update', 'bp_xprofile_reset_user_mid_cache', 10, 1 );
</ins></span></pre></div>
<a id="trunksrcbpxprofilebpxprofilefiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/bp-xprofile-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/bp-xprofile-filters.php 2021-03-21 14:17:21 UTC (rev 12868)
+++ trunk/src/bp-xprofile/bp-xprofile-filters.php 2021-03-22 19:45:24 UTC (rev 12869)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -352,6 +352,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function bp_xprofile_escape_field_data( $value, $field_type, $field_id ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Sanitization for these types is directly done into their `display_filter()` method.
+ if ( 'wp-biography' === $field_type || 'wp-textbox' === $field_type ) {
+ return $value;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( bp_xprofile_is_richtext_enabled_for_field( $field_id ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // The xprofile_filter_kses() expects a BP_XProfile_ProfileData object.
</span><span class="cx" style="display: block; padding: 0 10px"> $data_obj = null;
</span></span></pre></div>
<a id="trunksrcbpxprofilebpxprofilefunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/bp-xprofile-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/bp-xprofile-functions.php 2021-03-21 14:17:21 UTC (rev 12868)
+++ trunk/src/bp-xprofile/bp-xprofile-functions.php 2021-03-22 19:45:24 UTC (rev 12869)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -159,6 +159,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'textarea' => 'BP_XProfile_Field_Type_Textarea',
</span><span class="cx" style="display: block; padding: 0 10px"> 'textbox' => 'BP_XProfile_Field_Type_Textbox',
</span><span class="cx" style="display: block; padding: 0 10px"> 'telephone' => 'BP_XProfile_Field_Type_Telephone',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'wp-biography' => 'BP_XProfile_Field_Type_WordPress_Biography',
+ 'wp-textbox' => 'BP_XProfile_Field_Type_WordPress_Textbox',
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -311,6 +313,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Get a profile Field Type object.
+ *
+ * @since 8.0.0
+ *
+ * @param int $field_id ID of the field.
+ * @return BP_XProfile_Field_Type|null Field Type object if found, otherwise null.
+ */
+function bp_xprofile_get_field_type( $field_id ) {
+ $field_type = null;
+ $field = xprofile_get_field( $field_id, null, false );
+
+ if ( $field instanceof BP_XProfile_Field ) {
+ $field_type = $field->type_obj;
+ }
+
+ return $field_type;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Delete a profile field object.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.1.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -462,14 +483,42 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $field = new BP_XProfile_ProfileData();
- $field->field_id = $field_id;
- $field->user_id = $user_id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $field_args = compact( 'field_type_obj', 'field', 'user_id', 'value', 'is_required' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Gets un/reserialized via xprofile_sanitize_data_value_before_save().
- $field->value = maybe_serialize( $value );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Return a WP_Error object or true to use your custom way of saving field values.
+ *
+ * @since 8.0.0
+ *
+ * @param boolean Whether to shortcircuit the $bp->profile->table_name_data table.
+ * @param array $field_args {
+ * An array of arguments.
+ *
+ * @type object $field_type_obj Field type object.
+ * @type BP_XProfile_Field $field Field object.
+ * @type integer $user_id The user ID.
+ * @type mixed $value Value passed to xprofile_set_field_data().
+ * @type boolean $is_required Whether or not the field is required.
+ * }
+ */
+ $retval = apply_filters( 'bp_xprofile_set_field_data_pre_save', false, $field_args );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $field->save();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_wp_error( $retval ) ) {
+ return false;
+ }
+
+ if ( false === $retval ) {
+ $field = new BP_XProfile_ProfileData();
+ $field->field_id = $field_id;
+ $field->user_id = $user_id;
+
+ // Gets un/reserialized via xprofile_sanitize_data_value_before_save().
+ $field->value = maybe_serialize( $value );
+
+ $retval = $field->save();
+ }
+
+ return $retval;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1357,3 +1406,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'done' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Returns the list of supporterd WordPress field meta keys.
+ *
+ * @since 8.0.0
+ *
+ * @return string[] List of supported WordPress user keys.
+ */
+function bp_xprofile_get_wp_user_keys() {
+ return array_merge(
+ array( 'first_name', 'last_name', 'user_url', 'description' ),
+ array_keys( wp_get_user_contact_methods() )
+ );
+}
</ins></span></pre></div>
<a id="trunksrcbpxprofileclassesclassbpxprofilecomponentphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/classes/class-bp-xprofile-component.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/classes/class-bp-xprofile-component.php 2021-03-21 14:17:21 UTC (rev 12868)
+++ trunk/src/bp-xprofile/classes/class-bp-xprofile-component.php 2021-03-22 19:45:24 UTC (rev 12869)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -410,7 +410,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'bp_xprofile_data',
</span><span class="cx" style="display: block; padding: 0 10px"> 'bp_xprofile_fields',
</span><span class="cx" style="display: block; padding: 0 10px"> 'bp_xprofile_groups',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'xprofile_meta'
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'xprofile_meta',
+ 'bp_user_mid',
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> parent::setup_cache_groups();
</span></span></pre></div>
<a id="trunksrcbpxprofileclassesclassbpxprofileprofiledataphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/classes/class-bp-xprofile-profiledata.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/classes/class-bp-xprofile-profiledata.php 2021-03-21 14:17:21 UTC (rev 12868)
+++ trunk/src/bp-xprofile/classes/class-bp-xprofile-profiledata.php 2021-03-22 19:45:24 UTC (rev 12869)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -316,12 +316,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Get a user's profile data for a set of fields.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.0.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 8.0.0 Checks if a null field data is an xProfile WP Field.
+ * Adds a new parameter `$field_type_objects` to pass the list of field type objects.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $user_id ID of user whose data is being queried.
- * @param array $field_ids Array of field IDs to query for.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $user_id ID of user whose data is being queried.
+ * @param array $field_ids Array of field IDs to query for.
+ * @param array $field_type_objects Array of field type objects keyed by the queried filed IDs.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public static function get_data_for_user( $user_id, $field_ids ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function get_data_for_user( $user_id, $field_ids, $field_type_objects = array() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $data = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -339,6 +342,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $uncached_data as $ud ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $d = new stdClass;
</span><span class="cx" style="display: block; padding: 0 10px"> $d->id = $ud->id;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $d->table_name = $bp->profile->table_name_data;
</ins><span class="cx" style="display: block; padding: 0 10px"> $d->user_id = $ud->user_id;
</span><span class="cx" style="display: block; padding: 0 10px"> $d->field_id = $ud->field_id;
</span><span class="cx" style="display: block; padding: 0 10px"> $d->value = $ud->value;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -359,11 +363,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // If no value was found, cache an empty item
</span><span class="cx" style="display: block; padding: 0 10px"> // to avoid future cache misses.
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $d = new stdClass;
- $d->id = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $d = new stdClass;
+
+ // Check WordPress if it's a WordPress field.
+ if ( isset( $field_type_objects[ $field_id ]->wp_user_key ) ) {
+ $meta = $field_type_objects[ $field_id ]->get_field_value( $user_id, $field_id );
+ $d->id = $meta['id'];
+ $d->value = $meta['value'];
+ $d->table_name = $meta['table_name'];
+
+ } else {
+ $d->id = '';
+ $d->value = '';
+ }
+
+ $d->table_name = '';
</ins><span class="cx" style="display: block; padding: 0 10px"> $d->user_id = $user_id;
</span><span class="cx" style="display: block; padding: 0 10px"> $d->field_id = $field_id;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $d->value = '';
</del><span class="cx" style="display: block; padding: 0 10px"> $d->last_updated = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_cache_set( $cache_key, $d, 'bp_xprofile_data' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -396,6 +412,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Get all of the profile information for a specific user.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.2.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 8.0.0 Checks if a null field data is an xProfile WP Field.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $user_id ID of the user.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -430,8 +447,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'field_group_name' => $group->name,
</span><span class="cx" style="display: block; padding: 0 10px"> 'field_id' => $field->id,
</span><span class="cx" style="display: block; padding: 0 10px"> 'field_type' => $field->type,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'field_data' => $field->data->value,
</del><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( is_null( $field->data ) ) {
+ if ( 1 === $field->id ) {
+ $profile_data[ $field->name ]['field_data'] = $user->display_name;
+ } elseif ( isset( $field->type_obj ) && $field->type_obj instanceof BP_XProfile_Field_Type && isset( $field->type_obj->wp_user_key ) ) {
+ $meta = $field->type_obj->get_field_value( $user->ID, $field->id );
+
+ if ( isset( $meta['value'] ) ) {
+ $profile_data[ $field->name ]['field_data'] = $meta['value'];
+ }
+ } else {
+ $profile_data[ $field->name ]['field_data'] = false;
+ }
+ } else {
+ $profile_data[ $field->name ]['field_data'] = $field->data->value;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -475,6 +507,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Supports multiple user IDs.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.0.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 8.0.0 Checks if a null field data is an xProfile WP Field.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $field_id ID of the field.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int|array|null $user_ids ID or IDs of user(s).
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -524,11 +557,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // No data found for the user, so we fake it to
</span><span class="cx" style="display: block; padding: 0 10px"> // avoid cache misses and PHP notices.
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $d = new stdClass;
- $d->id = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $d = new stdClass;
+ $field_type = bp_xprofile_get_field_type( $field_id );
+
+ // Check WordPress if it's a WordPress field.
+ if ( isset( $field_type->wp_user_key ) ) {
+ $meta = $field_type->get_field_value( $user_id, $field_id );
+ $d->id = $meta['id'];
+ $d->value = $meta['value'];
+ $d->table_name = $meta['table_name'];
+
+ } else {
+ $d->id = '';
+ $d->value = '';
+ }
+
+ $d->table_name = '';
</ins><span class="cx" style="display: block; padding: 0 10px"> $d->user_id = $id;
</span><span class="cx" style="display: block; padding: 0 10px"> $d->field_id = $field_id;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $d->value = '';
</del><span class="cx" style="display: block; padding: 0 10px"> $d->last_updated = '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -570,6 +616,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Get profile field values by field name and user ID.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.0.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @deprecated 8.0.0 This function is not used anymore.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array|string $fields Field(s) to get.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int|null $user_id User ID to get field data for.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -576,6 +623,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array|bool
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function get_value_byfieldname( $fields, $user_id = null ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ _deprecated_function( __FUNCTION__, '8.0.0' );
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $fields ) ) {
</span></span></pre></div>
<a id="trunksrcbpxprofileclassesclassbpxprofileuseradminphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/classes/class-bp-xprofile-user-admin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/classes/class-bp-xprofile-user-admin.php 2021-03-21 14:17:21 UTC (rev 12868)
+++ trunk/src/bp-xprofile/classes/class-bp-xprofile-user-admin.php 2021-03-22 19:45:24 UTC (rev 12869)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -272,7 +272,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $r = bp_parse_args( $args['args'], array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'profile_group_id' => 0,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'user_id' => $user->ID
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'user_id' => $user->ID,
+ 'hide_field_types' => array( 'wp-textbox', 'wp-biography' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ), 'bp_xprofile_user_admin_profile_loop_args' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // We really need these args.
</span></span></pre></div>
<a id="trunksrcbpxprofilescreenseditphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-xprofile/screens/edit.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-xprofile/screens/edit.php 2021-03-21 14:17:21 UTC (rev 12868)
+++ trunk/src/bp-xprofile/screens/edit.php 2021-03-22 19:45:24 UTC (rev 12869)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -50,6 +50,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $posted_field_ids = wp_parse_id_list( $_POST['field_ids'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $is_required = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $bp_displayed_user = bp_get_displayed_user();
+ $bp_displayed_user->updated_keys = array();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Loop through the posted fields formatting any datebox values then validate the field.
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( (array) $posted_field_ids as $field_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> bp_xprofile_maybe_format_datebox_post_data( $field_id );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -126,6 +129,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> do_action( 'xprofile_updated_profile', bp_displayed_user_id(), $posted_field_ids, $errors, $old_values, $new_values );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Some WP User keys have been updated: let's update the WP fiels all together.
+ if ( $bp_displayed_user->updated_keys ) {
+ $user_id = wp_update_user(
+ array_merge(
+ array(
+ 'ID' => bp_displayed_user_id(),
+ ),
+ $bp_displayed_user->updated_keys
+ )
+ );
+
+ $bp_displayed_user->updated_keys = array();
+
+ if ( is_wp_error( $user_id ) ) {
+ $errors = true;
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Set the feedback messages.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( !empty( $errors ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> bp_core_add_message( __( 'There was a problem updating some of your profile information. Please try again.', 'buddypress' ), 'error' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -153,4 +174,4 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $template Path to the XProfile edit template to load.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> bp_core_load_template( apply_filters( 'xprofile_template_edit_profile', 'members/single/home' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-}
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+}
</ins></span></pre>
</div>
</div>
</body>
</html>