-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Framework: WP_Block: Use reflected type hint for render_callback #21833
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aduth
added
the
[Feature] Block API
API that allows to express the block paradigm.
label
Apr 23, 2020
aduth
requested review from
ajitbohra,
chrisvanpatten,
jorgefilipecosta,
mkaz,
nerrad,
ntwb,
Soean,
talldan,
TimothyBJacobs and
youknowriad
as code owners
April 23, 2020 16:11
Size Change: +23 B (0%) Total Size: 845 kB
ℹ️ View Unchanged
|
More pointed to what's expected (a WP_Block class type), and more supported in PHP versions
Tired, I am
Closing in favor of #21925. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #21797
Previously: #21467
This pull request seeks to revise the implementation of block context. As of #21467, the function signature of
render_callback
was revised in such a way that was intended to be backward-compatible, but which was not always the case in more advanced usage. With the changes proposed in this pull request, a block implementation must explicitly opt-in to receive the full block instance as the argument ofrender_callback
. This should be much more durable than the previous implementation, as existing implementations should not be affected at all, since they would in-fact be passed the same value (an array of attributes), not a value intending to simulate the same behavior (a class implementingArrayAccess
).From the block implementer's perspective, the developer can opt to receive the block instance by merely providing
WP_Block
as a type declaration on the first parameter:Existing use as an array is not impacted:
(Notably, the second code example does not work on the current
master
branch)Internally, the implementation uses function reflection to determine whether the render callback is expecting to receive the instance of the block, or the default associative array of block attributes.
Testing Instructions:
Repeat testing instructions from #21467. Optionally, it was made easier to test in later development of #21467, using the "Gutenberg Test Block Context" plugin included in the default development environment, via the associated "Test Context Provider" block.