diff --git a/themes/wporg-5ftf-2024/functions.php b/themes/wporg-5ftf-2024/functions.php index b67ceb7..43cf6f8 100644 --- a/themes/wporg-5ftf-2024/functions.php +++ b/themes/wporg-5ftf-2024/functions.php @@ -9,6 +9,7 @@ require_once __DIR__ . '/inc/block-config.php'; require_once __DIR__ . '/inc/block-bindings.php'; // Block files. +require_once __DIR__ . '/src/my-pledge-list/index.php'; require_once __DIR__ . '/src/pledge-contributors/index.php'; require_once __DIR__ . '/src/pledge-edit-button/index.php'; require_once __DIR__ . '/src/pledge-teams/index.php'; @@ -98,3 +99,27 @@ function add_body_class( $classes ) { } return $classes; } + +/** + * Filter the featured image to show an avatar on the `my-pledges` page. + * + * @param string $html The post thumbnail HTML. + * @param int $post_id The post ID. + * @param int $post_thumbnail_id The post thumbnail ID, or 0 if there isn't one. + * @param string|int[] $size Requested image size. Can be any registered image size name, or + * an array of width and height values in pixels (in that order). + * @param string|array $attr Query string or array of attributes. + * + * @return string Updated HTML. + */ +function swap_avatar_for_featured_image( $html, $post_id, $post_thumbnail_id, $size, $attr ) { + if ( is_page( 'my-pledges' ) && empty( $html ) ) { + $attr_str = ''; + foreach ( $attr as $name => $value ) { + $attr_str .= " $name=" . '"' . $value . '"'; + } + $html = get_avatar( wp_get_current_user(), 110, 'mystery', '', array( 'extra_attr' => $attr_str ) ); + } + return $html; +} +add_filter( 'post_thumbnail_html', __NAMESPACE__ . '\swap_avatar_for_featured_image', 10, 5 ); diff --git a/themes/wporg-5ftf-2024/inc/block-bindings.php b/themes/wporg-5ftf-2024/inc/block-bindings.php index 43fe5cc..038be2e 100644 --- a/themes/wporg-5ftf-2024/inc/block-bindings.php +++ b/themes/wporg-5ftf-2024/inc/block-bindings.php @@ -5,8 +5,9 @@ namespace WordPressdotorg\Theme\FiveForTheFuture_2024\Block_Bindings; +use WordPressDotOrg\FiveForTheFuture\XProfile; use function WordPressDotOrg\FiveForTheFuture\PledgeMeta\get_pledge_meta; -use function WordPressDotOrg\FiveForTheFuture\XProfile\get_aggregate_contributor_data_for_pledge; +use const WordPressDotOrg\FiveForTheFuture\Contributor\CPT_ID as CONTRIBUTOR_POST_TYPE; add_action( 'init', __NAMESPACE__ . '\register_block_bindings' ); @@ -48,7 +49,7 @@ function get_meta_binding_value( $args, $block ) { esc_html( $data['org-domain'] ) ); case 'org-contribution-details': - $contribution_data = get_aggregate_contributor_data_for_pledge( $block->context['postId'] ); + $contribution_data = XProfile\get_aggregate_contributor_data_for_pledge( $block->context['postId'] ); return sprintf( __( '%1$s sponsors %2$s for a total of %3$s hours per week across %4$d teams.', 'wporg-5ftf' ), get_the_title( $block->context['postId'] ), @@ -60,10 +61,42 @@ function get_meta_binding_value( $args, $block ) { count( $contribution_data['teams'] ) ); case 'org-contribution-short-details': - $contribution_data = get_aggregate_contributor_data_for_pledge( $block->context['postId'] ); + $contribution_data = XProfile\get_aggregate_contributor_data_for_pledge( $block->context['postId'] ); return sprintf( __( 'Has pledged %s hours per week.', 'wporg-5ftf' ), number_format_i18n( absint( $contribution_data['hours'] ) ), ); + case 'user-contribution-details': + $user = wp_get_current_user(); + if ( ! $user ) { + return ''; + } + + $profile_data = XProfile\get_contributor_user_data( $user->ID ); + + $contributor_publish_query = new \WP_Query( array( + 'title' => $user->user_login, + 'post_type' => CONTRIBUTOR_POST_TYPE, + 'post_status' => array( 'publish' ), + 'posts_per_page' => 100, + 'fields' => 'ids', + ) ); + $pledge_count = $contributor_publish_query->found_posts; + return wp_kses_data( sprintf( + /* translators: %1$s is the number of hours, %2$s is the number of organizations, and %3$s is an edit link. */ + _n( + 'Pledged %1$s hours a week %3$s across %2$s organization.', + 'Pledged %1$s hours a week %3$s across %2$s organizations.', + $pledge_count, + 'wporg-5ftf' + ), + $profile_data['hours_per_week'], + $pledge_count, + sprintf( + '%2$s', + __( 'edit hours pledged', 'wporg-5ftf' ), + __( '(edit)', 'wporg-5ftf' ) + ) + ) ); } } diff --git a/themes/wporg-5ftf-2024/patterns/my-pledges.php b/themes/wporg-5ftf-2024/patterns/my-pledges.php new file mode 100644 index 0000000..de581cd --- /dev/null +++ b/themes/wporg-5ftf-2024/patterns/my-pledges.php @@ -0,0 +1,37 @@ + + +
Pledged 40 hours a week (edit) across 1 organization.
+ ++ post_status ) { + echo esc_html( sprintf( + __( 'You confirmed this pledge on %s', 'wporg-5ftf' ), + gmdate( get_option( 'date_format' ), strtotime( $contributor_post->post_date ) ) + ) ); + } else { + echo esc_html_e( 'This organization would like to pledge your time', 'wporg-5ftf' ); + } + ?> +
+ + +