add_ping()为已有ping添加URL

目录

描述

译文

为已有ping添加URL

原文

Add a URL to those already pung.

add_ping() 描述

用法

<?php add_ping$post_id$uri ?>

add_ping() 用法

参数

$post_id

(integer) (必填) Post ID.

默认值: None

$uri

(string) (必填) Ping URI.

默认值: None

add_ping() 参数

返回值

(integer) 

Count of updated rows.

add_ping() 返回值

注意

add_ping() 注意

历史

添加于 版本: 1.5.0

add_ping() 历史

源文件

add_ping() 函数的代码位于 wp-includes/post.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Add a URL to those already pinged.
 *
 * @since 1.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int    $post_id Post ID.
 * @param string $uri     Ping URI.
 * @return int|false How many rows were updated.
 */
function add_ping( $post_id, $uri ) {
	global $wpdb;
	$pung = $wpdb->get_var( $wpdb->prepare( "SELECT pinged FROM $wpdb->posts WHERE ID = %d", $post_id ));
	$pung = trim($pung);
	$pung = preg_split('/s/', $pung);
	$pung[] = $uri;
	$new = implode("
", $pung);

	/**
	 * Filter 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 );

	// expected_slashed ($new).
	$new = wp_unslash($new);
	return $wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post_id ) );
}

add_ping() 源文件