-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(corrections): add corrections and clarifications behind feature flag #3638
feat(corrections): add corrections and clarifications behind feature flag #3638
Conversation
62eb69c
to
86453c4
Compare
86453c4
to
efdc46c
Compare
TODO:
|
e743872
to
63d997c
Compare
63d997c
to
94659b0
Compare
let hasSavedPost = false; | ||
const unsubscribe = subscribe( () => { | ||
// Return early if no new corrections have been added. | ||
if ( ! newCorrectionsCount ) { | ||
return; | ||
} | ||
const isSavingPost = select( 'core/editor' ).isSavingPost(); | ||
const isAutosavingPost = select('core/editor').isAutosavingPost(); | ||
|
||
if ( isSavingPost && ! isAutosavingPost && ! hasSavedPost ) { | ||
hasSavedPost = true; | ||
} | ||
|
||
if ( ! isSavingPost && hasSavedPost ) { | ||
// Unsubscribe from the store. | ||
unsubscribe(); | ||
window.location.href = window.location.href; | ||
} | ||
} ); | ||
} | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a super hacky way to force reload the page. We need to reload the page when adding new corrections so the metabox fields can repopulate with the respective correction ids (needed for updates and deleting). Ideally we remove this when we are able to fully work on the feature
Gonna mark this one ready for review since the core functionality is working and this should at least get us to a point where we can begin migrating corrections. After working on this, my thought is we should re-implement corrections as a new block. I did start working on this a bit, but realized this would imply some design decisions, so for the time being I've gone ahead and just pushed up a rework of our existing corrections custom plugin. cc @leogermani |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works and serves the purpose of unblocking migration.
There is just one warning being thrown at delete_corrections
method.
I left a few other non blocking comments
Another non-blocking comment: I think "activate corrections" and "position" should be a global setting, and not something per post... We can discuss it and I don't think this will be a blocker for migration now.... well... maybe we can get rid of the "activate" so it doesn't get in the way.
Finally, WDYT of adding a short README to the folder describing how the data is stored, to inform LEs that will work on the migration?
* @param array $correction_ids correction ids. | ||
*/ | ||
public static function delete_corrections( $correction_ids ) { | ||
$stored_correction_ids = get_post_meta( $post_id, self::CORRECTIONS_IDS_META, true ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$post_id
doesn't seem to be defined here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! Good catch. Fixed in fea9890
'public_queryable' => true, | ||
'query_var' => true, | ||
'rewrite' => [ 'slug' => 'correction' ], | ||
'show_ui' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want the UI for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also fixed in fea9890
'post_status' => 'publish', | ||
'meta_input' => [ | ||
self::CORRECTION_POST_ID_META => $post_id, | ||
self::CORRECTION_DATE_META => $correction['date'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not store the date using post_date?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this, but also considered corrections will be viewed in other contexts outside of a post (shortcode, archive, etc.) and so it might be useful to distinguish between the actual date a correction is published and the date assigned to a correction by a publisher as these might not always be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I actually thought that the date the correction was posted is not relevant, so we could use this field as the correction date.. no need to have two.
But I get your point. The only thing is that if we go this route, get_corrections
will have to order posts by a postmeta value, that will be a string. If we used the post_date this would be working out of the box
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a fair point. I've updated this to use post_date
instead in 13dbe29
* @param int $post_id The post ID. | ||
* @param array $corrections The corrections. | ||
*/ | ||
public static function save_corrections( $post_id, $corrections ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: naming it add_corrections
(or insert) would make the purpose of this method clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion! I am not very good at naming things. Fixed in fea9890
7a49db8
to
fea9890
Compare
Thanks for the review @leogermani!
I think position makes sense as a global setting, but do think it would be useful for publishers to be able to set whether corrections are active at the post level. For example, being able to publish a correction but not set it to active until it has been approved/verified. That said, I am open to any decision here.
Great idea! Added one here: https://github.com/Automattic/newspack-plugin/blob/fea98909ba23a62584c9f97bd3a2adc97bf1be2e/includes/corrections/README.md Let me know if I need to expand anywhere! |
Makes sense. We don't need to decide this now, it has little impact on the migration. Can I just suggest that this should be active by default? I'm thinking about LEs migrating data and wanting to look at the site to see if the data is there. Ideally they wouldn't need to add a "active = true" for every post and we'll think about it later |
That's fair. I've updated this in 0017f16 so when the meta is not present corrections will be shown. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the revisions!
Hey @chickenn00dle, good job getting this PR merged! 🎉 Now, the Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label. If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label. Thank you! ❤️ |
Removing needs-changelog label since this feature is strictly to prep for a migration and won't actually launch quite yet |
# [5.12.0-alpha.1](v5.11.1...v5.12.0-alpha.1) (2025-01-14) ### Bug Fixes * **cli:** verify-reader CLI command ([#3660](#3660)) ([c639af7](c639af7)) * **recaptcha:** replace alerts with generic errors ([#3627](#3627)) ([44ef2d2](44ef2d2)) * remove newspack_corrections_ids meta ([#3675](#3675)) ([dad258b](dad258b)) ### Features * **corrections:** add corrections and clarifications behind feature flag ([#3638](#3638)) ([ea745cf](ea745cf)) ### Performance Improvements * **data-events:** queue dispatches to execute on shutdown ([#3616](#3616)) ([510a1a0](510a1a0))
🎉 This PR is included in version 5.12.0-alpha.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
# [5.12.0](v5.11.3...v5.12.0) (2025-01-20) ### Bug Fixes * **cli:** verify-reader CLI command ([#3660](#3660)) ([c639af7](c639af7)) * **recaptcha:** replace alerts with generic errors ([#3627](#3627)) ([44ef2d2](44ef2d2)) * remove newspack_corrections_ids meta ([#3675](#3675)) ([dad258b](dad258b)) * **wcs:** migrate-expired-subscriptions handle manual subscriptions ([#3663](#3663)) ([e0f32e8](e0f32e8)) ### Features * **corrections:** add corrections and clarifications behind feature flag ([#3638](#3638)) ([ea745cf](ea745cf)) ### Performance Improvements * **data-events:** queue dispatches to execute on shutdown ([#3616](#3616)) ([510a1a0](510a1a0))
🎉 This PR is included in version 5.12.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
All Submissions:
Changes proposed in this Pull Request:
Closes https://app.asana.com/0/1208894036683495/1208945901567236 and https://app.asana.com/0/1208894036683495/1208945901567238
This PR adds the corrections feature behind the
NEWSPACK_CORRECTIONS_ENABLED
feature flag. Note this is a quick and simple implementation based on an already existing custom plugin strictly for the purpose of getting ready for a site migration.Editor:
Frontend:
How to test the changes in this Pull Request:
NEWSPACK_CORRECTIONS_ENABLED
)Other information: