ndiego / block-visibility

Conditional visibility controls for all WordPress blocks.
https://www.blockvisibilitywp.com
GNU General Public License v2.0
123 stars 10 forks source link

Necessity to have rewrite_rules created for the visibility_presets post_type #97

Closed carstingaxion closed 6 months ago

carstingaxion commented 8 months ago

Description

While working on some rewrite rules I mentioned the existence of rewrite_rules for the visibility_presets post_type.

[visibility_preset/[^/]+/attachment/([^/]+)/?$] => index.php?attachment=$matches[1]
[visibility_preset/[^/]+/attachment/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
[visibility_preset/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
[visibility_preset/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
[visibility_preset/[^/]+/attachment/([^/]+)/kommentar-seite-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
[visibility_preset/[^/]+/attachment/([^/]+)/embed/?$] => index.php?attachment=$matches[1]&embed=true
[visibility_preset/([^/]+)/embed/?$] => index.php?post_type=visibility_preset&name=$matches[1]&embed=true
[visibility_preset/([^/]+)/trackback/?$] => index.php?post_type=visibility_preset&name=$matches[1]&tb=1
[visibility_preset/([^/]+)/seite/?([0-9]{1,})/?$] => index.php?post_type=visibility_preset&name=$matches[1]&paged=$matches[2]
[visibility_preset/([^/]+)/kommentar-seite-([0-9]{1,})/?$] => index.php?post_type=visibility_preset&name=$matches[1]&cpage=$matches[2]
[visibility_preset/([^/]+)(?:/([0-9]+))?/?$] => index.php?post_type=visibility_preset&name=$matches[1]&page=$matches[2]
[visibility_preset/[^/]+/([^/]+)/?$] => index.php?attachment=$matches[1]
[visibility_preset/[^/]+/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
[visibility_preset/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
[visibility_preset/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
[visibility_preset/[^/]+/([^/]+)/kommentar-seite-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
[visibility_preset/[^/]+/([^/]+)/embed/?$] => index.php?attachment=$matches[1]&embed=true

And I was a little surprised, wondering if there could be any need to have this rules applied to every request on a website.

Step-by-step reproduction instructions

  1. Get some dump of get_option('rewrite_rules')

I also looked for rewrite, permalink, post_type_link and visibility_presets to find out any way you may use the rewrites within your code, with no luck, luckily.

Expected behavior

Remove the need for generated rewrite_rules by setting 'rewrite' => false, for the visibility_presets post_type. I could open a PR with this change, if you prefer.

Actual behavior

I guess having these rules generated might be just unwanted behaviour, because you already set 'public' => false, which is inherited to publicly_queryable, but not to rewrite.

https://github.com/ndiego/block-visibility/blob/728821e295e95cd158efc816b153ff282fcafbcd/includes/presets/register-presets.php#L22-L30

With your code in place, rewrite is set by default, to the post_type slug, which results in the generation of rewrite_rules for this particular post_type.

From the codex:

Triggers the handling of rewrites for this post type. To prevent rewrite, set to false. Defaults to true, using $post_type as slug.

Screenshots or screen recording (optional)

image

System information

ndiego commented 6 months ago

Thanks for logging this issue. Definitely an oversight. Just tested setting 'rewrite' => false, and everything works as expected. I added this in a076314, which will be included in the next release.

carstingaxion commented 6 months ago

Thanks for taking the time and even better you found it useful @ndiego!