wp_json_encode( array( 'host' => $host, 'key' => $key, 'urlList' => array( $url ), ) ), 'headers' => array( 'Content-Type' => 'application/json' ), 'timeout' => 5, 'blocking' => false, ) ); return ! is_wp_error( $response ); } /** * Hook into post publish/update to ping IndexNow. * * @param string $new_status New post status. * @param string $old_status Previous post status. * @param \WP_Post $post Post object. * @return void */ function indexnow_on_publish( string $new_status, string $old_status, \WP_Post $post ): void { if ( ! is_feature_enabled( 'indexnow' ) ) { return; } if ( $new_status !== 'publish' ) { return; } if ( wp_is_post_revision( $post->ID ) || wp_is_post_autosave( $post->ID ) ) { return; } $public_post_types = get_post_types( array( 'public' => true ) ); if ( ! in_array( $post->post_type, $public_post_types, true ) ) { return; } $url = get_permalink( $post ); if ( ! $url ) { return; } ping_indexnow( $url ); }