This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Feature/implement irving is main query #272
Open
jameswburke
wants to merge
9
commits into
main
Choose a base branch
from
feature/implement-irving-is-main-query
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
295c53c
Implement provide-site-theme and template-part components
jameswburke 88e9ae9
Tweak final components
jameswburke 0e52c48
Change name of site theme provider
jameswburke c2b5062
Update unit tests
jameswburke e223d8a
Merge branch 'update/IRV-350/fix-is-home-checks' into temp
jameswburke f68505d
Merge branch 'feature/new-components' into temp
jameswburke 01facd5
Implement an is_irving_main_query() utility function
jameswburke d6f6261
Add support for body classes
jameswburke 7260c09
Merge branch 'master' into feature/implement-irving-is-main-query
jameswburke 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
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
inc/components/components/site-theme-provider/component.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "irving/site-theme-provider", | ||
"_alias": "irving/fragment", | ||
"description": "Provide context from the Site Theme.", | ||
"config": { | ||
"default": { | ||
"default": null, | ||
"description": "The default argument for get_site_theme()." | ||
}, | ||
"selector": { | ||
"default": "", | ||
"description": "The selector argument for get_site_theme().", | ||
"type": "string" | ||
}, | ||
"value": {} | ||
}, | ||
"provides_context": { | ||
"irving/site-theme": "value" | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
inc/components/components/site-theme-provider/component.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Provider for get_site_theme(). | ||
* | ||
* Provide context from the Site Theme. | ||
* | ||
* @package WP_Irving | ||
*/ | ||
|
||
namespace WP_Irving\Components; | ||
|
||
use WP_Irving\Templates; | ||
|
||
/** | ||
* Register the component and callback. | ||
*/ | ||
register_component_from_config( | ||
__DIR__ . '/component', | ||
[ | ||
'config_callback' => function ( array $config ): array { | ||
$config['value'] = Templates\get_site_theme( $config['selector'] ?? '', $config['default'] ?? null ); | ||
return $config; | ||
}, | ||
] | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "irving/template-part", | ||
"_alias": "irving/fragment", | ||
"description": "Load a template part.", | ||
"config": { | ||
"slug": { | ||
"default": "", | ||
"description": "The slug used to locate the template part.", | ||
"type": "string" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Template part loader. | ||
* | ||
* Load a template part. | ||
* | ||
* @package WP_Irving | ||
*/ | ||
|
||
namespace WP_Irving\Components; | ||
|
||
use WP_Irving\Templates; | ||
|
||
/** | ||
* Register the component and callback. | ||
*/ | ||
register_component_from_config( | ||
__DIR__ . '/component', | ||
[ | ||
'children_callback' => function( array $children, array $config ): array { | ||
return Templates\hydrate_template_parts( | ||
[ | ||
'name' => 'template-parts/' . ( $config['slug'] ?? '' ), | ||
] | ||
); | ||
}, | ||
] | ||
); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/** | ||
* Irving functionality. | ||
* | ||
* @package WP_Irving | ||
*/ | ||
|
||
namespace WP_Irving; | ||
|
||
use WP_Irving\REST_API; | ||
|
||
/** | ||
* Irving equivelent to is_main_query(). True for the Components Endpoint | ||
* query. | ||
* | ||
* @return boolean | ||
*/ | ||
function is_main_irving_query() { | ||
return REST_API\Components_Endpoint::$is_main_irving_query; | ||
} |
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
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
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.
@joemcgill, I think we should consider adding this call to
query()
.If
$query
is empty in the constructor, thenquery()
never runs, which meansget_posts()
doesn't run, which means thepre_get_posts
hook never runs.Which means,
pre_get_posts
never runs on the index/home/front-page query, because$query
is an empty string.Looking for a gut-check from you if this makes sense, or there's something I'm not seeing here.
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.
I think that makes sense, though I'm curious what happens on a traditional home page load. I assume we are needing to work around this because normally on a home page load the query args would not be empty.
If we add this call to
query()
here we should be able to remove theparse_query()
call below, sinceWP_Query::query()
callsWP_Query::get_posts()
, which callsWP_Query::parse_query()
under the hood (see code).