mirror of
https://ghproxy.net/https://github.com/fairpm/fair-plugin.git
synced 2025-09-04 12:45:45 +08:00
Ping IndexNow for newly 404ing URLs. (#160)
Signed-off-by: Peter Wilson <git-commit-by@peterwilson.cc> Signed-off-by: Ryan McCue <me@ryanmccue.info> Co-authored-by: Ryan McCue <me@ryanmccue.info>
This commit is contained in:
parent
ffbc7559a7
commit
966c82949e
1 changed files with 38 additions and 5 deletions
|
@ -109,18 +109,51 @@ function handle_key_file_request() {
|
|||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
function ping_indexnow( $new_status, $old_status, $post ) : void {
|
||||
// Only ping for published posts.
|
||||
if ( 'publish' !== $new_status ) {
|
||||
/*
|
||||
* Skip if post type isn't viewable.
|
||||
*
|
||||
* The post type shouldn't change under normal circumstances,
|
||||
* so it's safe to assume that both the old and new post are
|
||||
* not viewable.
|
||||
*/
|
||||
if ( ! is_post_type_viewable( $post->post_type ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip revisions and autosaves.
|
||||
/*
|
||||
* Skip for revisions and autosaves.
|
||||
*
|
||||
* The IndexNow ping for revisions will be handled by the
|
||||
* parent post's transition_post_status hook.
|
||||
*/
|
||||
if ( wp_is_post_revision( $post ) || wp_is_post_autosave( $post ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip non-public post types.
|
||||
if ( ! is_post_type_viewable( $post->post_type ) ) {
|
||||
/*
|
||||
* Skip if both old and new statuses are private.
|
||||
*
|
||||
* The page will have been a 404 before and after.
|
||||
*
|
||||
* For pages that are newly a 404, still ping IndexNow
|
||||
* to encourage removal of the URL from search engines.
|
||||
*/
|
||||
if (
|
||||
! is_post_status_viewable( $new_status )
|
||||
&& ! is_post_status_viewable( $old_status )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prevent double pings for block editor legacy meta boxes.
|
||||
*/
|
||||
if (
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
isset( $_GET['meta-box-loader'] )
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.PHP.StrictComparisons.LooseComparison -- form input.
|
||||
&& '1' == $_GET['meta-box-loader']
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue