add_ping

Add a URL to those already pinged.

Description

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

Returns (int|false)

How many rows were updated.

Parameters (2)

0. $post_id (int|WP_Post)
Post object or ID.
1. $uri (string|array)
Ping URI or array of URIs.

Usage

  1. if ( !function_exists( 'add_ping' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Post object or ID. 
  5. $post_id = null; 
  6.  
  7. // Ping URI or array of URIs. 
  8. $uri = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = add_ping($post_id, $uri); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function add_ping( $post_id, $uri ) { 
  2. global $wpdb; 
  3.  
  4. $post = get_post( $post_id ); 
  5. if ( ! $post ) { 
  6. return false; 
  7.  
  8. $pung = trim( $post->pinged ); 
  9. $pung = preg_split( '/\s/', $pung ); 
  10.  
  11. if ( is_array( $uri ) ) { 
  12. $pung = array_merge( $pung, $uri ); 
  13. else { 
  14. $pung[] = $uri; 
  15. $new = implode("\n", $pung); 
  16.  
  17. /** 
  18. * Filters the new ping URL to add for the given post. 
  19. * @since 2.0.0 
  20. * @param string $new New ping URL to add. 
  21. */ 
  22. $new = apply_filters( 'add_ping', $new ); 
  23.  
  24. $return = $wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post->ID ) ); 
  25. clean_post_cache( $post->ID ); 
  26. return $return;