Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update speaker bio with job title and company #269

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions wp-content/themes/pub/wporg-learn-2020/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,41 +671,48 @@ function wporg_get_workshop_other_contributors( $workshop = null ) {
}

/**
* Get the bio of a user, first trying usermeta and then profiles.wordpress.org.
* Get the data of a user, first trying usermeta and then profiles.wordpress.org.
*
* The `usermeta` bio (description) field will be pulled. If there is no bio, profiles.wordpress.org is tried.
* The bio at profiles.wordpress.org relies on the availability of the `bpmain_bp_xprofile_data` table.
* For local environments the bio will only pull from `usermeta`.
* The `usermeta` fields will be pulled. If there is no data for either bio, job_title or company, profiles.wordpress.org is tried.
* The data at profiles.wordpress.org relies on the availability of the `bpmain_bp_xprofile_data` table.
* For local environments the data will only pull from `usermeta`.
*
* @param WP_User $user The user to retrieve a bio for.
*
* @return string
*/
function wporg_get_workshop_presenter_bio( WP_User $user ) {
function wporg_get_workshop_presenter_details( WP_User $user ) {
global $wpdb;

// Retrieve bio from user data.
$bio = $user->description;
$job_title = $user->job_title; // this will need to be changed to match live
$company = $user->company; // this will need to be changed to match live

// If bio is empty, retrieve from .org.
if ( ! $bio && 'local' !== wp_get_environment_type() ) {
$xprofile_field_id = 3;
// If any of bio, job title, and company is empty, retrieve from .org.
if ( ! ( $bio && $job_title && $company ) && 'local' !== wp_get_environment_type() ) {

$sql = $wpdb->prepare(
'
$sql = $wpdb->prepare( '
SELECT value
FROM bpmain_bp_xprofile_data
WHERE user_id = %1$d
AND field_id = %2$d
',
$user->ID,
$xprofile_field_id
AND field_id in (%2$d, %3$d, %4$d)
', $user->ID,
3, // bio id
4, // will need to be changed to match live
5 // will need to be changed to match live
);

$bio = $wpdb->get_var( $sql ) ?: ''; // phpcs:ignore WordPress.DB.PreparedSQL -- prepare called above.
$results = $wpdb->get_results($sql) ?: array(); // phpcs:ignore WordPress.DB.PreparedSQL -- prepare called above.

$bio = $bio ?: $results[0]->value;
$job_title = $job_title ?: $results[1]->value;
$company = $company ?: $results[2]->value;
}

return apply_filters( 'the_content', wp_unslash( $bio ) );
$user_data = compact( 'bio', 'job_title', 'company' );

return apply_filters( 'the_content', wp_unslash( $user_data ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ function( $other_contributor ) {
</div>

<div class="col-8 workshop-page_biography">
<?php echo wp_kses_post( wpautop( wporg_get_workshop_presenter_bio( $presenter ) ) ); ?>
<?php $user_data = wporg_get_workshop_presenter_details($presenter); ?>
<p><strong>
<?php echo wp_kses_post( wpautop( $user_data['job_title'] ) ); ?>
at
<?php echo wp_kses_post( wpautop( $user_data['company'] ) ); ?>.</strong></p>
<?php echo wp_kses_post( wpautop( $user_data['bio'] ) ); ?>
</div>
</div>
<?php endforeach; ?>
Expand Down