add_ping

Add a URL to those already pinged.

Description

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

Returns (int|false)

How many rows were updated.

Parameters (2)

0. $post_id (int)
The post id.
1. $uri (string)
Ping URI.

Usage

  1. if ( !function_exists( 'add_ping' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // The post id. 
  5. $post_id = -1; 
  6.  
  7. // Ping URI. 
  8. $uri = ''; 
  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. $pung = $wpdb->get_var( $wpdb->prepare( "SELECT pinged FROM $wpdb->posts WHERE ID = %d", $post_id )); 
  4. $pung = trim($pung); 
  5. $pung = preg_split('/\s/', $pung); 
  6. $pung[] = $uri; 
  7. $new = implode("\n", $pung); 
  8.  
  9. /** 
  10. * Filter the new ping URL to add for the given post. 
  11. * @since 2.0.0 
  12. * @param string $new New ping URL to add. 
  13. */ 
  14. $new = apply_filters( 'add_ping', $new ); 
  15.  
  16. // expected_slashed ($new). 
  17. $new = wp_unslash($new); 
  18. return $wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post_id ) );