-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[New block] bookmark and bookmark count #69660
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
[New block] bookmark and bookmark count #69660
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @rawdolphe. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@Mamaduka, @adamsilverstein & @gziolo I’d love to get your feedback on this PR! |
As far as I'm aware, all the new blocks are on hold for the time being. Please take a look at the discussion in #58773. |
@Mamaduka, as I understand it, new blocks—other than those listed in #58773—are not considered a priority since they don’t focus on individual needs. However, I believe these blocks should be included in the list, as they serve important functions and have broad use cases, such as bookmarks or wish lists, which could benefit a wide range of bloggers and large entities like news agencies. |
@sarthaknagoshe2002, the new block guidelines need to be written/updated. Unfortunately, currently, everyone is busy with the release. Until such guidelines are published, the referenced issue is all we have, and I would be hesitant to approve new blocks. This doesn't mean that work here should stop; I'm just trying to set the right expectations. |
@Mamaduka Okay then, in the meantime, we can refine this further and discuss any shortcomings. 😇🙌🏻 |
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's been a while since I've built anything similar, but I've left some surface notes regarding the code.
I think the best example of a Likes plugin I can remember in the WP ecosystem is this one - https://github.com/wearerequired/rest-likes. I'm sure we can learn a lot from it. cc @ocean90
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.
Sorry, I don't really understand what the point of this page is.
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 basically acts like an archive page which would display all the posts bookmarked/liked by the user at a single place
add_rewrite_rule( '^favorites/?$', 'index.php?pagename=favorites', 'top' ); | ||
add_rewrite_rule( '^favorites/page/([0-9]+)/?$', 'index.php?pagename=favorites&paged=$matches[1]', 'top' ); | ||
flush_rewrite_rules(); |
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.
Block shouldn't register any rewrite rules or flush them. Calling flush_rewrite_rules
on init
is a bad practice.
function block_core_bookmark_load_favorites_template( $template ) { | ||
global $wp; | ||
if ( isset( $wp->query_vars['pagename'] ) && 'favorites' === $wp->query_vars['pagename'] ) { // Ensure it's set | ||
status_header( 200 ); | ||
if ( ! is_user_logged_in() ) { | ||
wp_register_script( 'core-bookmarks-logged-out-user', '/wp-content/plugins/gutenberg/packages/block-library/src/bookmark/bookmarks-logged-out-user.js', array(), filemtime( '/wp-content/plugins/gutenberg/packages/block-library/src/bookmark/bookmarks-logged-out-user.js' ), true ); | ||
wp_enqueue_script( 'core-bookmarks-logged-out-user' ); | ||
} | ||
return 'wp-content/plugins/gutenberg/packages/block-library/src/bookmark/all-bookmarked.php'; | ||
} | ||
return $template; | ||
} | ||
add_filter( 'template_include', 'block_core_bookmark_load_favorites_template' ); |
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 goes against Site Editor principles, which require a PHP template to display the data.
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.
The issue mentions that this feature should also work for logged out users.
In that case the data will be stored on local storage, which would require a semi-ready template & a JS to read the local storage & add it to the page.
If the Site Editor principles doesn't allow that then what could be a better work around to achieve the aforementioned?
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 think Query Block or some other template can be used for logged-in users. If the decision is to introduce a new template, then that should be handled in the core.
Currently, PR seems to be trying to do too much at once. Maybe it's better to start with minimal requirements for the block(s), see if it gets approved and then work on enhancements, like logged-out user support.
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.
Currently, PR seems to be trying to do too much at once.
@sarthaknagoshe2002 maybe you can reduce this PR to just the Bookmark block itself, then have separate PRs for each "feature" on top of that, eg counter block, archive template and non logged in user support.
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.
@adamsilverstein On it! 😇🙌🏻
/** | ||
* Sets the page name. | ||
* | ||
* @since 6.8.0 | ||
*/ | ||
function block_core_bookmark_set_favorites_page_title( $title ) { | ||
global $wp; | ||
if ( isset( $wp->query_vars['pagename'] ) && 'favorites' === $wp->query_vars['pagename'] ) { | ||
$title['title'] = 'Favorite Posts'; | ||
} | ||
return $title; | ||
} | ||
add_filter( 'document_title_parts', 'block_core_bookmark_set_favorites_page_title' ); |
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'm guessing this updates the document title tag. All human-readable user-facing strings need to be translated.
As per the feedbacks I have created 3 different PRs for each feature & also addressed a few feedbacks 😇 |
What?
This PR adds a bookmarking/favorites system for WordPress posts, allowing users to save posts for later reading. The feature includes:
Closes #59524
Why?
Currently, WordPress lacks a built-in way for users to bookmark or favorite posts for later reading. This is an essential feature for content-heavy sites, similar to YouTube’s Watch Later or social media Saved Posts features.
How?
Testing Instructions
Note
$src
inwp_register_script()
is supposed to be like@wordpress/script_path
which didn't seemed to work for me, it will be rectified as per feedback & guidance.Screenshots or screencast
Editor side
editor.mov
Logged out users
Screen.Recording.2025-03-22.at.10.31.41.PM.mov
Logged in users
logged.in.mov