Skip to content
This repository was archived by the owner on Jul 28, 2023. It is now read-only.

Process directive attributes with a colon (e.g. wp-bind:value) - #151

Merged
DAreRodz merged 4 commits into
main-wp-directives-pluginfrom
fix/directives-with-colon
Feb 16, 2023
Merged

DAreRodz merged 4 commits into
main-wp-directives-pluginfrom
fix/directives-with-colon

Conversation

@DAreRodz

Copy link
Copy Markdown
Collaborator

What

The title is self-explanatory. 🙂

Why

Right now, directives using a colon are not processed and thus ignored because they're not found inside $attribute_directives:

https://github.com/WordPress/block-hydration-experiments/blob/b3df431c3436bb5f41fede36b9307cd5d770dd67/wp-directives.php#L219-L224

How

Simply filtering the colon and the part that follows from attributes before doing the search.

@DAreRodz DAreRodz added the bug Something isn't working label Feb 16, 2023
@DAreRodz
DAreRodz requested a review from ockham February 16, 2023 11:19
Comment on lines +33 to +38
// Helper that removes the part after the colon before looking
// for the directive processor inside `$attribute_directives`.
$get_directive_type = function ( $attr ) {
return strtok( $attr, ':' );
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we maybe move this outside wp_process_directives's function definition so we don't re-define the $get_directive_type ever so often?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Would it be fine if we create a global function just for that? That feels weird, haha. 😅

Anyway, we can do it in another PR if you think is worth it. 👍

@ockham ockham left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice find! I think I probably messed something up in #144 with regard to this kind of directive.

Great to have it fixed, and covered by a unit test 🎉 Also confirming that the test fails if I don’t apply the fix ✅ Thank you very much!

I left two minor suggestions -- otherwise LGTM!

Co-authored-by: Bernie Reiter <ockham@raz.or.at>
@DAreRodz

Copy link
Copy Markdown
Collaborator Author

Thanks for your review and feedback, @ockham! 🙏

@DAreRodz
DAreRodz merged commit 1457628 into main-wp-directives-plugin Feb 16, 2023
@DAreRodz
DAreRodz deleted the fix/directives-with-colon branch February 16, 2023 17:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants