Skip to content
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

Patterns: add delete_posts to the wp_block (patterns) capabilities #53405

Merged
merged 3 commits into from
Aug 10, 2023

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Aug 8, 2023

Maybe resolves #53367

What?

Adds delete_posts to the wp_block (patterns) capabilities.

WordPress core backport PR:

Why?

It's currently not possible to delete draft posts. The wp_block post type has delete_published_posts in the capabilities array only.

See: https://github.com/WordPress/wordpress-develop/blob/444bdf49bc38883f603a584bcc119aedf98257b8/src/wp-includes/post.php#L322

How?

Using the register_{$post_type}_post_type_args hook.

Testing Instructions

  1. Add a pattern in the post editor (wp-admin/edit.php?post_type=wp_block)
  2. Save it in draft status
  3. Go back to the list table
  4. Try to trash the pattern (the row action will not be there)

Screenshots or screencast

Before

2023-08-08.14.13.56.mp4

After

2023-08-08.14.14.24.mp4

@ramonjd ramonjd added [Type] Bug An existing feature does not function as intended [Block] Pattern Affects the Patterns Block Needs PHP backport Needs PHP backport to Core labels Aug 8, 2023
@ramonjd ramonjd self-assigned this Aug 8, 2023
@ramonjd ramonjd changed the title Adding delete_posts to the wp_block (patterns) capabilities Patterns: add delete_posts to the wp_block (patterns) capabilities Aug 8, 2023
@github-actions
Copy link

github-actions bot commented Aug 8, 2023

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ lib/compat/wordpress-6.4/blocks.php
❔ lib/load.php

Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix here @ramonjd 👍

✅ Could replicate original issue
✅ Applying this PR allows deletion of draft pattern

I only had one minor question that I left via an inline comment. Pending that though, I'm happy to approve this.

Before After
Screenshot 2023-08-10 at 11 07 43 am Screenshot 2023-08-10 at 11 08 29 am

lib/compat/wordpress-6.4/blocks.php Outdated Show resolved Hide resolved
@ramonjd ramonjd force-pushed the add/wp-block-delete-posts-capabilities branch from 37e85c4 to c592cc7 Compare August 10, 2023 04:58
@ramonjd
Copy link
Member Author

ramonjd commented Aug 10, 2023

I tried to add tests for this PR, but for some reason current_user_can( 'delete_post', $draft_wp_block_id ) returns true all the time. But not here in core. 🤷🏻

Maybe something I'm missing in the way that the admin page works in this context.

…nce of `$args['capabilities']` before typing checking. If the first expression fails we skip the second, otherwise there'll be a PHP error.
@ramonjd ramonjd merged commit 530deb6 into trunk Aug 10, 2023
50 checks passed
@ramonjd ramonjd deleted the add/wp-block-delete-posts-capabilities branch August 10, 2023 06:12
@github-actions github-actions bot added this to the Gutenberg 16.5 milestone Aug 10, 2023
@ramonjd ramonjd removed the Needs PHP backport Needs PHP backport to Core label Aug 10, 2023
@mikachan mikachan added Needs PHP backport Needs PHP backport to Core and removed Needs PHP backport Needs PHP backport to Core labels Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Pattern Affects the Patterns Block [Type] Bug An existing feature does not function as intended
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

WP 6.3-RC3: it is not possible to trash patterns with draft status in post editor
3 participants