mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-05 10:25:45 +03:00
Theme: Single pledge view (#43)
* Theme: Create template part for single pledge * Plugin: Add functions for handling xprofile data * Plugin: Add helper function for getting contributor user objects * Theme: Display aggregated contributor data on single pledge view * Theme: Add functions, markup, and styles to show team badges * Theme: Add badge for Test team * Theme: Add tentative URL for report a pledge link * Theme: Add support for post thumbnails * Theme: Add org logo to single pledge view * Theme: Update `$content_width` to 960 This matches the width of the content in the global header and the About page. * Move pledge template to a file used by the template heirarchy * Clean up some PHPCS errors * Move pledge structure out to just the list items * Create file for single pledge styles * style badge grid into a grid. * Add a custom image size for the logo * Update styles * Un-hide pledges with no confirmed contributors * Fix content width
This commit is contained in:
parent
2ec665bcbb
commit
dbdcf26bd9
17 changed files with 683 additions and 53 deletions
|
@ -3,7 +3,7 @@ namespace WordPressDotOrg\FiveForTheFuture\Contributor;
|
|||
|
||||
use WordPressDotOrg\FiveForTheFuture;
|
||||
use WordPressDotOrg\FiveForTheFuture\Pledge;
|
||||
use WP_Error, WP_Post;
|
||||
use WP_Error, WP_Post, WP_User;
|
||||
|
||||
defined( 'WPINC' ) || die();
|
||||
|
||||
|
@ -196,3 +196,16 @@ function get_pledge_contributors( $pledge_id, $status = 'publish', $contributor_
|
|||
|
||||
return $posts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user objects that correspond with pledge contributor posts.
|
||||
*
|
||||
* @param WP_Post[] $contributor_posts
|
||||
*
|
||||
* @return WP_User[]
|
||||
*/
|
||||
function get_contributor_user_objects( array $contributor_posts ) {
|
||||
return array_map( function( WP_Post $post ) {
|
||||
return get_user_by( 'login', $post->post_title );
|
||||
}, $contributor_posts );
|
||||
}
|
||||
|
|
|
@ -193,9 +193,10 @@ function filter_query( $query ) {
|
|||
'type' => 'NUMERIC',
|
||||
);
|
||||
|
||||
if ( CPT_ID === $query->get( 'post_type' ) ) {
|
||||
$query->set( 'meta_query', $meta_queries );
|
||||
}
|
||||
// @todo Re-enable this check once pledges are public.
|
||||
// if ( CPT_ID === $query->get( 'post_type' ) ) {
|
||||
// $query->set( 'meta_query', $meta_queries );
|
||||
// }
|
||||
|
||||
// Searching is restricted to pledges only.
|
||||
if ( $query->is_search ) {
|
||||
|
|
85
plugins/wporg-5ftf/includes/xprofile.php
Normal file
85
plugins/wporg-5ftf/includes/xprofile.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
namespace WordPressDotOrg\FiveForTheFuture\XProfile;
|
||||
|
||||
use WordPressDotOrg\FiveForTheFuture\Contributor;
|
||||
use wpdb;
|
||||
|
||||
defined( 'WPINC' ) || die();
|
||||
|
||||
/**
|
||||
* Pull relevant data from profiles.wordpress.org.
|
||||
*
|
||||
* Note that this does not unserialize anything, it just pulls the raw values from the database table.
|
||||
*
|
||||
* @global wpdb $wpdb
|
||||
*
|
||||
* @param array $user_ids
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_xprofile_contribution_data( array $user_ids ) {
|
||||
global $wpdb;
|
||||
|
||||
// The IDs of the xprofile fields we need. Better to use the numerical IDs than the field labels,
|
||||
// because those are more likely to change.
|
||||
$field_ids = array(
|
||||
29, // Hours per week.
|
||||
30, // Teams, the value of this field is serialized in the database.
|
||||
);
|
||||
|
||||
$sql = $wpdb->prepare(
|
||||
'
|
||||
SELECT user_id, field_id, value
|
||||
FROM bpmain_bp_xprofile_data
|
||||
WHERE user_id IN ( %1$s )
|
||||
AND field_id IN ( %2$s )
|
||||
',
|
||||
implode( ', ', array_map( 'absint', $user_ids ) ),
|
||||
implode( ', ', array_map( 'absint', $field_ids ) )
|
||||
);
|
||||
|
||||
return $wpdb->get_results( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB.PreparedSQL -- prepare called above.
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregate the raw xprofile data for all contributors linked to a given pledge.
|
||||
*
|
||||
* @param int $pledge_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_aggregate_contributor_data_for_pledge( $pledge_id ) {
|
||||
$contributors = Contributor\get_contributor_user_objects(
|
||||
// TODO set to 'publish' when finished testing.
|
||||
Contributor\get_pledge_contributors( $pledge_id, 'pending' )
|
||||
);
|
||||
$user_ids = wp_list_pluck( $contributors, 'ID' );
|
||||
|
||||
$data = get_xprofile_contribution_data( $user_ids );
|
||||
|
||||
$initial = array(
|
||||
'contributors' => count( $user_ids ),
|
||||
'hours' => 0,
|
||||
'teams' => array(),
|
||||
);
|
||||
|
||||
$aggregate_data = array_reduce( $data, function( $carry, $item ) {
|
||||
switch ( $item['field_id'] ) {
|
||||
case 29: // Hours.
|
||||
$carry['hours'] += absint( $item['value'] );
|
||||
break;
|
||||
|
||||
case 30: // Teams.
|
||||
$value = maybe_unserialize( $item['value'] );
|
||||
$carry['teams'] = array_merge( $carry['teams'], $value );
|
||||
break;
|
||||
}
|
||||
|
||||
return $carry;
|
||||
}, $initial );
|
||||
|
||||
$aggregate_data['teams'] = array_unique( $aggregate_data['teams'] );
|
||||
sort( $aggregate_data['teams'] );
|
||||
|
||||
return $aggregate_data;
|
||||
}
|
|
@ -29,6 +29,7 @@ function load() {
|
|||
require_once get_includes_path() . 'pledge-meta.php';
|
||||
require_once get_includes_path() . 'pledge-form.php';
|
||||
require_once get_includes_path() . 'directory.php';
|
||||
require_once get_includes_path() . 'xprofile.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue