Making WordPress.org


Ignore:
Timestamp:
11/21/2022 04:19:12 AM (2 years ago)
Author:
dd32
Message:

Profiles: Add a method to allow non-profiles.wordpress.org sites to update xProfile fields.

Pre-set the users profile website field with the data from registration.

See #518.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/profile-helpers.php

    r12122 r12254  
    22
    33/*
    4  * These functions provide a simple interface for other plugins to add/remove badges and activity entries from
    5  * profiles.w.org.
     4 * These functions provide a simple interface for other plugins to modify WordPress.org Profile data, such as badges, activity entries, and xProfile fields.
    65 *
    7  * See `api.w.org/includes/profiles/profiles.php` for a similar function that is tailored to the API.
     6 * See `api.w.org/includes/profiles/profiles.php` for a similar badge function that is tailored to the API.
    87 */
    98
    109namespace WordPressdotorg\Profiles;
    11 use WP_Error;
     10use WP_Error, WP_User;
    1211
    1312/**
     
    4948        'user'      => $user,
    5049        'args'      => $args,
     50    ] );
     51
     52    return ( 200 === wp_remote_retrieve_response_code( $request ) );
     53}
     54
     55/**
     56 * Update a BuddyPress profile field with a value.
     57 *
     58 * @param $field string      The profile field name to update.
     59 * @param $value mixed       The value to update it to.
     60 * @param $user  int|WP_User The user object or user ID to update.
     61 * @return bool
     62 */
     63function update_profile( $field, $value, $user ) {
     64    $request = api( [
     65        'action' => 'wporg_update_profile',
     66        'user'   => $user instanceOf WP_User ? $user->ID : $user,
     67        'fields' => [
     68            $field => $value
     69        ],
    5170    ] );
    5271
Note: See TracChangeset for help on using the changeset viewer.