Skip to content

Five for the Future: Count only the hours a contributor gives through each pledge - #417

Open
ekamran wants to merge 1 commit into
WordPress:productionfrom
ekamran:shifteq/pledge-hours-split
Open

ekamran wants to merge 1 commit into
WordPress:productionfrom
ekamran:shifteq/pledge-hours-split

Conversation

@ekamran

@ekamran ekamran commented Oct 8, 2026

Copy link
Copy Markdown

Fixes #72.

Contributors can now split their weekly hours on their profile, between each sponsor and their own time. The pledge side still adds each contributor's full profile total to every pledge that sponsors them. So own time counts as sponsored, and a contributor with two sponsors adds their full total to both pledges.

For example, my profile form submits wporg_5ftf_hours[296004]=4 for the ShifteQ pledge, wporg_5ftf_hours[self]=2 for my own time, and field_29=6 as the total. The ShifteQ pledge counts all 6, so it shows 9 hours per week instead of 7.

What changes

  • New XProfile\get_contributor_hours_splits() reads the splits for a list of users in one query.
  • get_aggregate_contributor_data_for_pledge() counts only the hours a contributor gives through that pledge, when they have a split. The pledge sentences, the cached 5ftf_pledge-total-hours meta and the sort by hours all use it, so they follow.
  • Stats\get_snapshot_data() counts the self part of a company-sponsored contributor's split as self-sponsored hours.
  • With no split, or a split with no hours in it, the full total counts, same as today. A pledge never gets more than the contributor's total.

Not changed: contributor and team counts, the contributor report (it still shows each contributor's total), and remove_contributor().

One thing to confirm

The split is saved by profiles.wordpress.org, and that code is not public. Going by the form field names, I assumed it is stored as user meta wporg_5ftf_hours, an array like array( 296004 => 4, 'self' => 2 ). @obenland, can you confirm where it is stored? If it is somewhere else, only the split reader should need to change. Until then the code finds no split and every number stays as it is today, so nothing gets worse.

Related: #201 asked for the split on the profile, and #372 is about attributing contributions to more than one sponsor.

Testing

  • 7 new tests in test-xprofile.php and test-stats.php. Four of them fail before the fix. The other three guard today's behaviour (no split, an empty split, a split above the total) and pass on both sides. Full suite: 53 tests, green, run twice.
  • Each part of the fix was broken on purpose (7 mutants), and each one was caught by the test written for it.
  • Runtime on wp-env (WordPress 7.2-alpha, PHP 8.3) with a pledge shaped like ShifteQ's: one contributor with 6 hours split 4 + 2, two others with 2 and 1. Before: the pledge shows 9 hours and the stats count 9 company-sponsored hours. After: 7 and 7, and the 2 own hours move to self-sponsored.
  • phpcs shows no new warnings on the changed files.

AI assistance: Claude Code and Codex helped with the investigation, tests and wording. I reviewed the code and the test results, and I take responsibility for the change.

… each pledge

Contributors can split their weekly hours on their profile between their sponsors and their own time. The pledge total still added each contributor's full profile total to every pledge that sponsors them, and the stats counted their own time as company-sponsored.

Read the splits in one query, count only the pledge's share toward the pledge, and count the own-time part of a company-sponsored contributor's split as self-sponsored in the stats snapshot. Without a split, the full total counts as before.

Fixes WordPress#72.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Profiles data isn't granular enough when multiple companies sponsor a contributor

1 participant