Repository navigation
Conversation
788ef83 to
0b9c5ec
Compare
59f12a5 to
7db0121
Compare
Fixes WordPress#1180. The three figures on the front cover were hardcoded for the launch and set by hand since. They now come from the chapter program's Meetup groups, through the client WordCamp Reports uses, plus the WordCamps on central: past events + WordCamps since 2006, groups and the countries they're in, and members. Events and members round down to a clean figure with a plus. An hourly cron computes and stores them in an option; the page only ever reads the stored figures, so the Meetup API is never on a visitor's request, a failed fetch keeps the last figures, and until the first refresh the page shows the copy it launched with. A small server-rendered block, wporg/events-stat, renders one figure as a paragraph and keeps the pattern's colour and font-size settings; the front cover pattern uses three of them. @wordpress/i18n joins the theme's devDependencies for the editor labels.
7db0121 to
550b3ee
Compare
bor0
left a comment
There was a problem hiding this comment.
The refresh cron fatals on every run, so the figures never get stored and the homepage stays on the fallback copy.
count_wordcamps() passes 'fields' => 'ids' to get_wordcamps(), which then sets ->meta on each result: Attempt to assign property "meta" on int in 4-helpers-wcpt.php:42. Reproduced with wp cron event run wporg_events_refresh_stats --url=events.wordpress.test. The tests miss it because they always short-circuit wporg_events_stats_wordcamp_count.
Fix: switch to central and count with get_posts() (post_type => 'wordcamp', fields => 'ids', numberposts => -1) or a direct count query. Please don't just drop fields, that loads every camp's meta hourly. Add a test that runs the real count.
With that patched locally, everything else worked: the cron stores the figures, the cards render them, the fallback shows before the first run, and the block works in the editor with the Stat panel.
Minor: edit.js uses the wordcamporg text domain, PHP and block.json use wporg.
`get_wordcamps()` sets `->meta` on every result, so with `'fields' => 'ids'` the hourly refresh fataled and the figures were never stored. Count the scheduled and closed camps on central with `get_posts()` IDs instead, so no meta is loaded, and test the real count through the cron hook. Also use the `wordcamporg` text domain in the stats PHP and block.json to match edit.js, which the repo's i18n lint rule pins to `wordcamporg`.
|
Thanks, good catch. Fixed in 987677f:
Events 2023 suite: 48/48 on PHP 8.4. phpcs is clean on the changed files. |
Fixes #1180. Supersedes #2173 (closed), since the pattern no longer carries numbers at all.
The homepage stats were hardcoded for the 2023 launch, bumped by hand in #1359, and set by hand again
in the site editor on 2026-09-30. They now come from the data and refresh themselves.
What the three figures are
The same three the live page shows today, defined the way @karenalma's 2026-09-30 figures were:
past_event_countfrom the Meetup API, the same client WordCamp Reports uses) plus the WordCamps on central (wcpt-scheduledandwcpt-closedposts)member_count, summedThat follows the 2023 thread's call for all-time totals (@StevenDufresne, @thetinyl). It differs from
the issue's original sketch in one way: the thread had events and countries coming from
wporg_events,but that table only holds what the importer has synced, not everything since 2006, and the live copy
has since been redefined around the groups. Events and members are rounded down to a clean figure
with a plus (nearest 1,000 and 10,000), since the exact numbers change by the hour; groups and
countries are shown exactly.
How it works
inc/stats.phpcomputes the figures and stores them in an option. An hourly cron(
wporg_events_refresh_stats) fetches the groups throughMeetup_Client::get_groups()and countsthe WordCamps on central. Visitors never wait on the Meetup API: the page reads the stored figures
only. If the API fails or returns nothing, the stored figures stay. Until the first refresh has run,
the page shows the copy it launched with (the 2026-09-30 figures), so deploying this changes nothing
visible.
wporg/events-stat, with one attribute,stat(events, groups ormembers). It renders one sentence as a
<p>and keeps the pattern's colour and font-size settingsthrough block supports. In the editor it uses
ServerSideRender, with the stat picked in theinspector.
patterns/front-cover.phpuses three of those blocks instead of three hardcoded paragraphs.Screenshots
None needed for the front end: with the stored figures, the page renders exactly what it shows today.
The block appears in the editor as the rendered sentence with a "Stat" panel in the inspector.
How to test the changes in this Pull Request:
npm run buildin the theme. Load the homepage on a site with the theme's front page template:the three stats read as they do on production today (the fallback), since nothing is stored yet.
wp cron event run wporg_events_refresh_stats --url=events.wordpress.test,with Meetup API credentials configured. Reload: the figures are the computed ones.
sentence, and the inspector's "Stat" panel switches between the three.
Verification
Rebased onto
upstream/productionat5683a89f. It no longer includes #2171: the tests now sit inthe Events 2023 Theme suite that #1561 added, and load
inc/stats.phpand the block'sindex.phpthemselves, the way that suite's other tests do.
--testsuite "Events 2023 Theme", PHP 8.4.25 and 8.5.11 withlog_errors=1production, same container, PHP 8.4phpcs-branch.phpagainstproductionwp-scripts lint-json the new blocknpm run buildbuild/events-stat/hasblock.json,index.js,index.asset.phpTest_Stats(8):compute_stats()sums the groups' past events and the WordCamps, counts groups,counts each country once whatever the case, and sums members;
format_stat()rounds large figuresdown with a plus, shows small ones exactly, and returns nothing for an unknown stat;
get_stats()falls back to the launch copy with no data; a refresh stores what it computed; a failed or empty fetch
keeps the last figures; the refresh is scheduled hourly, once; the block renders the sentence as a
paragraph and nothing for an unknown stat. The Meetup call and the central query sit behind two
filters (
wporg_events_stats_groups,wporg_events_stats_wordcamp_count) that the tests use tosupply data; nothing in the tests touches the API.
Notes for reviewers
autoload does the same job without an expiry gap: if cron is late, the last figures stay up rather
than falling back.
@wordpress/i18nis added to the theme's devDependencies (6.21.0, the version the otherpackages pin), for the editor labels. The root lockfile change is three lines, regenerated with npm
10 to match CI's Node 20.
build/is absent, so a checkout that hasn't runnpm run builddoesn't emit a_doing_it_wrong; production builds on deploy.editor), so it still has the three static paragraphs. To get the dynamic figures on
events.wordpress.org, replace those three paragraphs with Events Stat blocks in the site editor once,
or reset the template to the theme default.