Infinite Scroll: Improved rendering callbacks w/ WooCommerce support#9120
Merged
dereksmart merged 10 commits intomasterfrom Mar 27, 2018
Merged
Infinite Scroll: Improved rendering callbacks w/ WooCommerce support#9120dereksmart merged 10 commits intomasterfrom
dereksmart merged 10 commits intomasterfrom
Conversation
Previously, if you ran `is_main_query`, it would return false during the `pre_get_posts` hook because `is_main_query` compares the current query to the global. By setting to global first, these checks can be done correctly.
…own renderers without conflicts.
… is not inherited from main query
zinigor
approved these changes
Mar 27, 2018
Contributor
zinigor
left a comment
There was a problem hiding this comment.
This is great! Testing this, looks like it really fixes the old IS problem with custom post types and sorting. Well done!
Contributor
Author
|
Added a commit to fix a theme conflict reported by @jeffikus and .com themes. |
|
Thanks @mikejolley busy testing now. |
|
Update: |
This was referenced Sep 10, 2020
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
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.
Adds basic WooCommerce support in the 3rd party scripts directory for WooCommerce.
This branch was branched from #9112 which will need reviewing and merging first.
The following changes are all related to WooCommerce and other plugin compatibility and are hence grouped into this single PR.
Posts per page changes
The current system is quite odd; it uses a fixed number of 7 or the 'posts per page' setting in WP Admin. This isn't suitable for custom post types where they have their own posts_per_page setting or preference. WC is a perfect example whereby posts_per_page is set to match our products grid.
To make this more robust we pass through the posts per page setting from the original query and use this instead.
If the theme defines a different
posts_per_pagevalue, we can default to that.Render callbacks
The previous system relied on a setting, and a fallback, for the render callback. One could also use
infinite_scroll_renderaction.There are a few problems with this:
infinite_scroll_renderaction, and the only way to prevent other callbacks outputting things is toremove_actionOur solution is to have a filter of registered callbacks which get ran in sequence. If a callback returns nothing (perhaps wrong post type is being shown?), it continues to the next until content is returned. Callbacks registered through theme support are still called, and the final fallback is the default
rendermethod in infinite scroll class.The filter is
infinite_scroll_render_callbacks. So example use:With this example it would call the following functions/methods in this order until content is returned:
my_post_render_callback()my_product_render_callback()add_theme_supportThe_Neverending_Home_Page::render()WooCommerce compatibility
All we need to do on this side is use the correct template for the content and render our wrappers. This should be fairly standard to any theme.
jetpack_woocommerce_infinite_scroll_renderdoes the rendering of this loop, andjetpack_woocommerce_infinite_scroll_render_callbackregisters this renderer using the system outlined above.jetpack_woocommerce_infinite_scroll_stylesimply hides the default numbered pagination WooCommerce outputs with CSS.