add_ping() WordPress Function

The add_ping() function enables you to add a pingback URL to your post. A pingback is a special type of comment that is created when someone links to your post from their own site. When a pingback is created, the other site's server will notify your site, and your site will then display the pingback in the comments section of the post.

add_ping( int|WP_Post $post_id, string|array $uri ) #

Add a URL to those already pinged.


Parameters

$post_id

(int|WP_Post)(Required)Post object or ID.

$uri

(string|array)(Required)Ping URI or array of URIs.


Top ↑

Return

(int|false) How many rows were updated.


Top ↑

Source

File: wp-includes/post.php

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

	$post = get_post( $post_id );

	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;
}


Top ↑

Changelog

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

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More