Campaign metrics are returned for at most one post per stats request
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start in src/rest-api/stats/class-endpoint-posts.php at Endpoint_Posts::fetch_campaign_data() around line 507, then read the posts stats endpoint flow and the campaign response matching logic. Reproduce with the documented two-post request and a mocked response that returns the second post first. Done means each post receives its matching campaign metrics without undefined-key or null-offset warnings.
Written by the indexing model from the issue text.
Description
Describe the bug
Endpoint_Posts::fetch_campaign_data() finds each post's campaign data with array_filter(), which keeps the original keys, and then reads the match as $campaign_post[0] (src/rest-api/stats/class-endpoint-posts.php:507). That only works for the post whose data is the first item of the campaign response, so at most one post per request gets its campaign metrics.
For every other post, $campaign_post[0] is undefined, all four campaign metrics become null, and GET /wp-parsely/v2/stats/posts returns "campaign": [] for it. The Engagement Boost dashboard reads campaign.views for its "+N" smart-link views and its "BOOSTED" percentage (src/content-helper/dashboard-page/components/posts-table/components/single-post-row.tsx:106), so neither appears for those posts.
To Reproduce
- Request
GET /wp-parsely/v2/stats/posts?campaign_id=wp-parsely&campaign_medium=smart-link&period_start=30dfor two posts that both have smart-link views, as the Engagement Boost dashboard does. - Have the campaign request return the second post first. Mocking the API with
pre_http_requestmakes this deterministic.
The post whose campaign data comes second gets "campaign": []. PHP raises Undefined array key 0 at class-endpoint-posts.php:507, followed by eight Trying to access array offset on null warnings at :510–:513.
Expected behavior
Each post gets the campaign metrics that match its link, wherever they appear in the campaign response.
Environment
wp-parsely 3.26.1 and current develop, PHP 8.3. PHP 7.4 raises notices instead of warnings.
Additional context
Possible fixes: take the match with reset(), or index the campaign response by link once before the loop, which also avoids filtering the whole response for every post.
- Dominant language
- PHP
- Stars
- 67
- Forks
- 38
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 79
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Parsely/wp-parsely
-
Bug Feature: Engagement Boost wp-parsely
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Parsely/wp-parsely#4856 ·
Maintainers usually reply within 1 day
-
Bug Feature: Engagement Boost wp-parsely
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Parsely/wp-parsely#4855 ·
Maintainers usually reply within 1 day
-
wp-parsely
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Parsely/wp-parsely#4753 ·
Maintainers usually reply within 1 day
-
Bug wp-parsely
Difficulty 4/5 3-5 days Newbie friendliness 58/100
Parsely/wp-parsely#4663 ·
Maintainers usually reply within 1 day
-
Documentation wp-parsely
Difficulty 3/5 1-2 days Newbie friendliness 74/100
Parsely/wp-parsely#4559 ·
Maintainers usually reply within 1 day
All issues in Parsely/wp-parsely
Similar issues
-
15.0
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
opnsense/plugins#5976 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
open-telemetry/opentelemetry-php-distro#176 ·
Maintainers usually reply within 2 days
-
No Code Attached Yet
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
joomla/joomla-cms#48941 ·
Maintainers usually reply within 1 day
-
needs-triage Platform(Default)
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day