-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Implement functions to check whether the current request is a REST request and whether a REST endpoint request is currently being handled #5658
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
Closed
felixarntz
wants to merge
11
commits into
WordPress:trunk
from
felixarntz:enhance/42061-rest-check-functions
Closed
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
63d9e57
Implement functions to check whether a REST request is being made and…
felixarntz e251d98
Get rid of unnecessarily strict _doing_it_wrong().
felixarntz 44a8960
Avoid editing Gutenberg block file managed via dependency.
felixarntz 2a2716b
Merge branch 'trunk' into enhance/42061-rest-check-functions
felixarntz a009157
Fix for wrong merge resolution.
felixarntz 59c8fb1
Remove method_exists() check.
felixarntz 67c85b7
Rename wp_is_rest_request() to wp_is_serving_rest_request().
felixarntz 32a27c6
Remove return types.
felixarntz 97ce714
Add tests and fix critical logic bug.
felixarntz d63898c
Merge branch 'trunk' into enhance/42061-rest-check-functions
felixarntz e09b4a0
Use bool cast instead of ! empty check.
felixarntz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Get rid of unnecessarily strict _doing_it_wrong().
- Loading branch information
commit e251d98747d87b3fef87ca8c73b9caf06682986b
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
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.
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.
Setting a return type slows this function down by about 20%
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.
@sybrew I'm not sure where you get this from. In any case, I am sure the time this function takes is irrelevant in the grand scheme of things, since it's just a constant check.
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.
@felixarntz every time a value is returned, its type is checked. This requires more processing time. Simply allowing to pass the value unchecked executes no additional code, so that's faster.
I'm trying to prevent this from becoming the norm. PHP isn't typed and nothing has been done to optimize type hinting thus far for userland. It's only a waste of resources.
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.
@sybrew That's fair. It probably requires a larger discussion, not in a specific ticket like this. I'm not sure what I think about it yet, but it looks like this would be the first return type in core anyway, so I'll just leave it out. Done in 32a27c6
Uh oh!
There was an error while loading. Please reload this page.
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.
(Crosstalk) There's also no need to crash a user's site because a wrong type is used during development. Just make sure this doesn't happen; it's easily achievable. We have PHPDoc, static code checks, and unit testing to help us with this. We write the code, so we can ascertain the return type without type hinting.