Skip to content

Commit 9b2bbe0

Browse files
committed
Add preflight filter to ping IndexNow.
1 parent bf65015 commit 9b2bbe0

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

inc/namespace.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,33 @@ function get_indexnow_key(): string {
132132
* @param WP_Post $post Post object.
133133
*/
134134
function maybe_ping_indexnow( $new_status, $old_status, $post ): void {
135+
/**
136+
* Filter to preflight the IndexNow ping.
137+
*
138+
* This allow for developers to provide custom logic to determine whether
139+
* to ping IndexNow. Return `true` to ping, `false` to skip, or
140+
* `null` to use the default logic.
141+
*
142+
* @param bool|null $preflight_ping The preflight ping decision.
143+
* Default is `null`, meaning use the default logic.
144+
* @param string $new_status The new post status.
145+
* @param string $old_status The old post status.
146+
* @param WP_Post $post The post object.
147+
*/
148+
$preflight_ping = apply_filters( 'pwcc/index-now/pre-maybe-ping-indexnow', null, $new_status, $old_status, $post );
149+
150+
if ( is_bool( $preflight_ping ) ) {
151+
if ( true === $preflight_ping ) {
152+
/**
153+
* Fire the action to ping IndexNow.
154+
*
155+
* @param WP_Post $post The post object.
156+
*/
157+
do_action( 'pwcc/index-now/ping', $post );
158+
}
159+
return;
160+
}
161+
135162
// Do not ping during an import.
136163
if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
137164
return;
@@ -175,11 +202,7 @@ function maybe_ping_indexnow( $new_status, $old_status, $post ): void {
175202
return;
176203
}
177204

178-
/**
179-
* Fire the action to ping IndexNow.
180-
*
181-
* @param WP_Post|int $post The post ID or object.
182-
*/
205+
/** This action is documented in inc/namespace.php */
183206
do_action( 'pwcc/index-now/ping', $post );
184207
}
185208

0 commit comments

Comments
 (0)