add_ping( int|WP_Post $post, string|array $uri ): int|false

In this article

Adds a URL to those already pinged.

Parameters

$postint|WP_Postrequired
Post ID or post object.
$uristring|arrayrequired
Ping URI or array of URIs.

Return

int|false How many rows were updated.

Source

function add_ping( $post, $uri ) {
	global $wpdb;

	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	$pung = trim( $post->pinged );
	$pung = preg_split( '/\s/', $pung );

	if ( is_array( $uri ) ) {
		$pung = array_merge( $pung, $uri );
	} else {
		$pung[] = $uri;
	}
	$new = implode( "\n", $pung );

	/**
	 * Filters the new ping URL to add for the given post.
	 *
	 * @since 2.0.0
	 *
	 * @param string $new New ping URL to add.
	 */
	$new = apply_filters( 'add_ping', $new );

	$return = $wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post->ID ) );
	clean_post_cache( $post->ID );
	return $return;
}

Hooks

apply_filters( ‘add_ping’, string $new )

Filters the new ping URL to add for the given post.

Changelog

VersionDescription
4.7.0$uri can be an array of URIs.
1.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.