# pingback()

URL: https://chugunov.pro/api-wordpress/functions/pingback/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 0.71.

## Сигнатура

```php
pingback( string $content, int|WP_Post $post ): array<string,
```

## Описание

Отправляет пингбэки по ссылкам, найденным в записи.

## Параметры

- `$content` `string` — обязательный. Содержимое записи для поиска ссылок. Если пусто, будет получено из записи.
- `$post` `int|WP_Post` — обязательный. Идентификатор или объект записи.

## Возвращаемое значение

`array<string,`

## Исходный код

Файл: `wp-includes/comment.php:3176`

```php
function pingback( $content, $post ) {
	require_once ABSPATH . WPINC . '/class-IXR.php';
	require_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';

	// Original code by Mort (http://mort.mine.nu:8080).
	$post_links = array();

	$post = get_post( $post );

	if ( ! $post ) {
		return array();
	}

	$pung = get_pung( $post );

	if ( empty( $content ) ) {
		$content = $post->post_content;
	}

	/*
	 * Step 1.
	 * Parsing the post, external links (if any) are stored in the $post_links array.
	 */
	$post_links_temp = wp_extract_urls( $content );

	$ping_status = array();
	/*
	 * Step 2.
	 * Walking through the links array.
	 * First we get rid of links pointing to sites, not to specific files.
	 * Example:
	 * http://dummy-weblog.org
	 * http://dummy-weblog.org/
	 * http://dummy-weblog.org/post.php
	 * We don't wanna ping first and second types, even if they have a valid <link/>.
	 */
	foreach ( (array) $post_links_temp as $link_test ) {
		// If we haven't pung it already and it isn't a link to itself.
		if ( ! in_array( $link_test, $pung, true ) && ( url_to_postid( $link_test ) !== $post->ID )
			// Also, let's never ping local attachments.
			&& ! is_local_attachment( $link_test )
		) {
			$test = parse_url( $link_test );
			if ( $test ) {
				if ( isset( $test['query'] ) ) {
					$post_links[] = $link_test;
				} elseif ( isset( $test['path'] ) && ( '/' !== $test['path'] ) && ( '' !== $test['path'] ) ) {
					$post_links[] = $link_test;
				}
			}
		}
	}

	$post_links = array_unique( $post_links );

	/**
	 * Fires just before pinging back links found in a post.
	 *
	 * @since 2.0.0
	 *
	 * @param string[] $post_links Array of link URLs to be checked (passed by reference).
	 * @param string[] $pung       Array of link URLs already pinged (passed by reference).
	 * @param int      $post_id    The post ID.
	 */
	do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post->ID ) );

	foreach ( (array) $post_links as $pagelinkedto ) {
		$pingback_server_url = discover_pingback_server_uri( $pagelinkedto );

		if ( $pingback_server_url ) {
			// Allow an additional 60 seconds for each pingback to complete.
			if ( function_exists( 'set_time_limit' ) ) {
				set_time_limit( 60 );
			}

			// Now, the RPC call.
			$pagelinkedfrom = get_permalink( $post );

			// Using a timeout of 3 seconds should be enough to cover slow servers.
			$client          = new WP_HTTP_IXR_Client( $pingback_server_url );
			$client->timeout = 3;
			/**
			 * Filters the user agent sent when pinging-back a URL.
			 *
			 * @since 2.9.0
			 *
			 * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
			 *                                    and the WordPress version.
			 * @param string $useragent           The useragent.
			 * @param string $pingback_server_url The server URL being linked to.
			 * @param string $pagelinkedto        URL of page linked to.
			 * @param string $pagelinkedfrom      URL of page linked from.
			 */
			$client->useragent = apply_filters( 'pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo( 'version' ), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom );
			// When set to true, this outputs debug messages by itself.
			$client->debug = false;

			$status = $client->query( 'pingback.ping', $pagelinkedfrom, $pagelinkedto );

			if ( $status // Ping registered.
				|| ( isset( $client->error->code ) && 48 === $client->error->code ) // Already registered.
			) {
				add_ping( $post, $pagelinkedto );
			}
			$ping_status[ $pagelinkedto ] = $status;
		}
	}

	return $ping_status;
}
```

## История изменений

- 6.8.0 — Returns an array of pingback statuses indexed by link.
- 4.7.0 — $post can be a WP_Post object.
- 0.71 — Introduced.

## Связанные

Использует: [`wp_extract_urls`](https://chugunov.pro/api-wordpress/functions/wp_extract_urls/), [`do_action_ref_array`](https://chugunov.pro/api-wordpress/functions/do_action_ref_array/), [`get_pung`](https://chugunov.pro/api-wordpress/functions/get_pung/), [`is_local_attachment`](https://chugunov.pro/api-wordpress/functions/is_local_attachment/), [`add_ping`](https://chugunov.pro/api-wordpress/functions/add_ping/), [`url_to_postid`](https://chugunov.pro/api-wordpress/functions/url_to_postid/), `WP_HTTP_IXR_Client::__construct`, [`discover_pingback_server_uri`](https://chugunov.pro/api-wordpress/functions/discover_pingback_server_uri/), [`get_bloginfo`](https://chugunov.pro/api-wordpress/functions/get_bloginfo/), [`get_permalink`](https://chugunov.pro/api-wordpress/functions/get_permalink/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`get_post`](https://chugunov.pro/api-wordpress/functions/get_post/).
Используется в: [`do_all_pingbacks`](https://chugunov.pro/api-wordpress/functions/do_all_pingbacks/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/pingback/
