-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add Sitemaps Functionality #310
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
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
33e8ced
First pass at integrating sitemaps
swissspidy e64139a
sitemap-sub-type -> sitemap-subtype
swissspidy 770b9b5
Better canonical integration
swissspidy 4097dcd
Lint fixes
swissspidy e12ac98
Don’t add WP_SITEMAPS_MAX_URLS constant
swissspidy 29ba5df
Remove l10n helpers for now
swissspidy e28056c
Update redirect_canonical integration
swissspidy aba9a35
Minor fixes
swissspidy 3aed523
Update from plugin
swissspidy 7e8e4d3
Add type hints
swissspidy b9b5bc2
Downstream changes
swissspidy a19379e
Try getting new docker images
swissspidy 5cda6d5
Downstream changes
swissspidy faed912
Add `wp_sitemaps_posts_show_on_front_entry` filter
swissspidy c22a018
Revert temp changes to local env
swissspidy 8053ef7
Try: improve esc_xml
swissspidy fa95dc1
Simplify `\WP_Sitemaps_Index::get_index_url()`
swissspidy 8acb95b
Update phpdoc for esc_xml
swissspidy 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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| <?php | ||
| /** | ||
| * Sitemaps: Public functions | ||
| * | ||
| * This file contains a variety of public functions developers can use to interact with | ||
| * the XML Sitemaps API. | ||
| * | ||
| * @package WordPress | ||
| * @subpackage Sitemaps | ||
|
swissspidy marked this conversation as resolved.
|
||
| * @since 5.5.0 | ||
| */ | ||
|
|
||
| /** | ||
| * Retrieves the current Sitemaps server instance. | ||
| * | ||
| * @since 5.5.0 | ||
| * | ||
| * @return WP_Sitemaps|null Sitemaps instance, or null if sitemaps are disabled. | ||
| */ | ||
| function wp_sitemaps_get_server() { | ||
| /** | ||
| * Global Core Sitemaps instance. | ||
| * | ||
| * @since 5.5.0 | ||
| * | ||
| * @var WP_Sitemaps $wp_sitemaps | ||
| */ | ||
| global $wp_sitemaps; | ||
|
|
||
| $is_enabled = (bool) get_option( 'blog_public' ); | ||
|
|
||
| /** | ||
| * Filters whether XML Sitemaps are enabled or not. | ||
| * | ||
| * @since 5.5.0 | ||
| * | ||
| * @param bool $is_enabled Whether XML Sitemaps are enabled or not. Defaults to true for public sites. | ||
| */ | ||
| $is_enabled = (bool) apply_filters( 'wp_sitemaps_is_enabled', $is_enabled ); | ||
|
swissspidy marked this conversation as resolved.
|
||
|
|
||
| if ( ! $is_enabled ) { | ||
| return null; | ||
| } | ||
|
|
||
| // If there isn't a global instance, set and bootstrap the sitemaps system. | ||
| if ( empty( $wp_sitemaps ) ) { | ||
| $wp_sitemaps = new WP_Sitemaps(); | ||
| $wp_sitemaps->init(); | ||
|
|
||
| /** | ||
| * Fires when initializing the Sitemaps object. | ||
| * | ||
| * Additional sitemaps should be registered on this hook. | ||
| * | ||
| * @since 5.5.0 | ||
| * | ||
| * @param WP_Sitemaps $sitemaps Server object. | ||
| */ | ||
| do_action( 'wp_sitemaps_init', $wp_sitemaps ); | ||
| } | ||
|
|
||
| return $wp_sitemaps; | ||
| } | ||
|
|
||
| /** | ||
| * Gets a list of sitemap providers. | ||
| * | ||
| * @since 5.5.0 | ||
| * | ||
| * @return array $sitemaps A list of registered sitemap providers. | ||
| */ | ||
| function wp_get_sitemaps() { | ||
| $sitemaps = wp_sitemaps_get_server(); | ||
|
|
||
| if ( ! $sitemaps ) { | ||
| return array(); | ||
| } | ||
|
|
||
| return $sitemaps->registry->get_sitemaps(); | ||
| } | ||
|
|
||
| /** | ||
| * Registers a new sitemap provider. | ||
| * | ||
| * @since 5.5.0 | ||
| * | ||
| * @param string $name Unique name for the sitemap provider. | ||
| * @param WP_Sitemaps_Provider $provider The `Sitemaps_Provider` instance implementing the sitemap. | ||
| * @return bool Returns true if the sitemap was added. False on failure. | ||
| */ | ||
| function wp_register_sitemap( $name, WP_Sitemaps_Provider $provider ) { | ||
| $sitemaps = wp_sitemaps_get_server(); | ||
|
|
||
| if ( ! $sitemaps ) { | ||
| return false; | ||
| } | ||
|
|
||
| return $sitemaps->registry->add_sitemap( $name, $provider ); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the maximum number of URLs for a sitemap. | ||
| * | ||
| * @since 5.5.0 | ||
| * | ||
| * @param string $object_type Object type for sitemap to be filtered (e.g. 'post', 'term', 'user'). | ||
| * @return int The maximum number of URLs. | ||
| */ | ||
| function wp_sitemaps_get_max_urls( $object_type ) { | ||
| /** | ||
| * Filters the maximum number of URLs displayed on a sitemap. | ||
| * | ||
| * @since 5.5.0 | ||
| * | ||
| * @param int $max_urls The maximum number of URLs included in a sitemap. Default 2000. | ||
| * @param string $object_type Object type for sitemap to be filtered (e.g. 'post', 'term', 'user'). | ||
| */ | ||
| return apply_filters( 'wp_sitemaps_max_urls', 2000, $object_type ); | ||
| } | ||
Oops, something went wrong.
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.
I would love a more detailed description here that explains why someone would use this function rather than
esc_attr()oresc_html().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.
We can probably update the docblocks of the other functions too while we're at it. Currently they're a bit bleak...
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.
will see what I can come up with that's a) more helpful that what's there and b) shorter than a dissertation :-)