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.

+ +
+ +
+ + + +
+ + + + + +
+ diff --git a/themes/wporg-5ftf-2024/src/my-pledge-list/block.json b/themes/wporg-5ftf-2024/src/my-pledge-list/block.json new file mode 100644 index 0000000..9aa3c56 --- /dev/null +++ b/themes/wporg-5ftf-2024/src/my-pledge-list/block.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "wporg/my-pledge-list", + "version": "0.1.0", + "title": "My pledges", + "category": "design", + "icon": "", + "description": "List out the pledges for this user.", + "textdomain": "wporg", + "supports": { + "html": false + }, + "editorScript": "file:./index.js", + "style": "file:./style-index.css", + "render": "file:./render.php" +} diff --git a/themes/wporg-5ftf-2024/src/my-pledge-list/index.js b/themes/wporg-5ftf-2024/src/my-pledge-list/index.js new file mode 100644 index 0000000..7d53dd9 --- /dev/null +++ b/themes/wporg-5ftf-2024/src/my-pledge-list/index.js @@ -0,0 +1,26 @@ +/** + * WordPress dependencies + */ +import { registerBlockType } from '@wordpress/blocks'; +import { useBlockProps } from '@wordpress/block-editor'; +import ServerSideRender from '@wordpress/server-side-render'; + +/** + * Internal dependencies + */ +import metadata from './block.json'; +import './style.scss'; + +const Edit = ( { attributes, name } ) => { + const blockProps = useBlockProps(); + return ( +
+ +
+ ); +}; + +registerBlockType( metadata.name, { + edit: Edit, + save: () => null, +} ); diff --git a/themes/wporg-5ftf-2024/src/my-pledge-list/index.php b/themes/wporg-5ftf-2024/src/my-pledge-list/index.php new file mode 100644 index 0000000..45cd1ec --- /dev/null +++ b/themes/wporg-5ftf-2024/src/my-pledge-list/index.php @@ -0,0 +1,135 @@ +post_parent ); + setup_postdata( $post ); + ob_start(); + ?> + +
+ +
+ +
+ + + +
+ +
+ + + +

+ 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' ); + } + ?> +

+ + +
+
+ + + post_status ) : ?> + ID ); ?> + +
+ + disabled="disabled" + + /> +
+ +
+ +
+ + post_status ) : ?> + ID ); ?> + +
+ +
+ + + +
+
+
+ +
+ +
+ + + +
+
+

+
+ + ID ); +$pledge_url = get_permalink( get_page_by_path( 'for-organizations' ) ); +$success_message = Contributor\process_my_pledges_form(); + +$contributor_pending_posts = get_posts( array( + 'title' => $user->user_login, + 'post_type' => CONTRIBUTOR_POST_TYPE, + 'post_status' => array( 'pending' ), + 'numberposts' => 100, +) ); + +$contributor_publish_posts = get_posts( array( + 'title' => $user->user_login, + 'post_type' => CONTRIBUTOR_POST_TYPE, + 'post_status' => array( 'publish' ), + 'numberposts' => 100, +) ); + +$has_contributions = $contributor_pending_posts || $contributor_publish_posts; +$has_profile_data = $profile_data['hours_per_week'] && $profile_data['team_names']; + +?> +
+> +
'; + } + ?> + + + + + +
+ +
+ + + + + +
+

+ + update your profile before joining an organization.', 'wporg-5ftf' ), + 'https://profiles.wordpress.org/me/profile/edit/group/5/' + ) + ); + } + + foreach ( $contributor_pending_posts as $contributor_post ) { + render_single_pledge( $contributor_post, $has_profile_data ); + } + ?> +
+ + + + + + submit a pledge and list you as a contributor.', 'wporg-5ftf' ), + esc_url( $pledge_url ) + ) ); ?> + + + + + diff --git a/themes/wporg-5ftf-2024/src/my-pledge-list/style.scss b/themes/wporg-5ftf-2024/src/my-pledge-list/style.scss new file mode 100644 index 0000000..905e830 --- /dev/null +++ b/themes/wporg-5ftf-2024/src/my-pledge-list/style.scss @@ -0,0 +1,18 @@ +.my-pledges__list > * + * { + margin-top: var(--wp--preset--spacing--60); +} + +.my-pledges__list.is-pending-list > .wp-block-wporg-notice { + margin-top: var(--wp--preset--spacing--20); +} + +.my-pledges__pledge-actions { + .wp-block-button { + display: inline-block; + + [disabled="disabled"] { + --wp--custom--button--color--background: var(--wp--preset--color--blueberry-2); + pointer-events: none; + } + } +} diff --git a/themes/wporg-5ftf-2024/src/style/_pledge-form.scss b/themes/wporg-5ftf-2024/src/style/_pledge-form.scss index 738398f..0559a93 100644 --- a/themes/wporg-5ftf-2024/src/style/_pledge-form.scss +++ b/themes/wporg-5ftf-2024/src/style/_pledge-form.scss @@ -51,6 +51,24 @@ } } + .form-field__logo-display { + box-sizing: content-box; + padding: var(--wp--preset--spacing--20); + border-color: var(--wp--preset--color--light-grey-1); + border-style: solid; + border-width: 1px; + border-radius: 2px; + background-color: var(--wp--preset--color--light-grey-2); + aspect-ratio: 1; + width: 275px; + + img { + width: 100%; + height: 100%; + object-fit: contain; + } + } + .form-field__agree { display: flex; gap: var(--wp--preset--spacing--10); diff --git a/themes/wporg-5ftf-2024/templates/page-my-pledges.html b/themes/wporg-5ftf-2024/templates/page-my-pledges.html new file mode 100644 index 0000000..c11fc4e --- /dev/null +++ b/themes/wporg-5ftf-2024/templates/page-my-pledges.html @@ -0,0 +1,15 @@ + + + +
+ + + +
+ + + + + + +