mirror of
git://develop.git.wordpress.org/
synced 2025-03-20 20:09:53 +01:00
Pings/Trackbacks: Add return value to pingback()
.
Some checks are pending
Cleanup Pull Requests / Clean up pull requests (push) Waiting to run
Coding Standards / PHP coding standards (push) Waiting to run
Coding Standards / JavaScript coding standards (push) Waiting to run
Coding Standards / Slack Notifications (push) Blocked by required conditions
Coding Standards / Failed workflow tasks (push) Blocked by required conditions
End-to-end Tests / Test with SCRIPT_DEBUG disabled (push) Waiting to run
End-to-end Tests / Test with SCRIPT_DEBUG enabled (push) Waiting to run
End-to-end Tests / Slack Notifications (push) Blocked by required conditions
End-to-end Tests / Failed workflow tasks (push) Blocked by required conditions
JavaScript Tests / QUnit Tests (push) Waiting to run
JavaScript Tests / Slack Notifications (push) Blocked by required conditions
JavaScript Tests / Failed workflow tasks (push) Blocked by required conditions
Performance Tests / Determine Matrix (push) Waiting to run
Performance Tests / ${{ matrix.multisite && 'Multisite' || 'Single Site' }} ${{ matrix.memcached && 'Memcached' || 'Default' }} (push) Blocked by required conditions
Performance Tests / Compare (push) Blocked by required conditions
Performance Tests / Slack Notifications (push) Blocked by required conditions
Performance Tests / Failed workflow tasks (push) Blocked by required conditions
PHP Compatibility / Check PHP compatibility (push) Waiting to run
PHP Compatibility / Slack Notifications (push) Blocked by required conditions
PHP Compatibility / Failed workflow tasks (push) Blocked by required conditions
PHPUnit Tests / PHP 7.2 (push) Waiting to run
PHPUnit Tests / PHP 7.3 (push) Waiting to run
PHPUnit Tests / PHP 7.4 (push) Waiting to run
PHPUnit Tests / PHP 8.0 (push) Waiting to run
PHPUnit Tests / PHP 8.1 (push) Waiting to run
PHPUnit Tests / PHP 8.2 (push) Waiting to run
PHPUnit Tests / PHP 8.3 (push) Waiting to run
PHPUnit Tests / PHP 8.4 (push) Waiting to run
PHPUnit Tests / html-api-html5lib-tests (push) Waiting to run
PHPUnit Tests / Slack Notifications (push) Blocked by required conditions
PHPUnit Tests / Failed workflow tasks (push) Blocked by required conditions
Test Build Processes / Core running from build (push) Waiting to run
Test Build Processes / Core running from src (push) Waiting to run
Test Build Processes / Gutenberg running from build (push) Waiting to run
Test Build Processes / Gutenberg running from src (push) Waiting to run
Test Build Processes / Slack Notifications (push) Blocked by required conditions
Test Build Processes / Failed workflow tasks (push) Blocked by required conditions
Upgrade Develop Version Tests / Build (push) Waiting to run
Upgrade Develop Version Tests / Upgrade from 6.5 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.6 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.7 (push) Blocked by required conditions
Upgrade Develop Version Tests / Slack Notifications (push) Blocked by required conditions
Upgrade Develop Version Tests / Failed workflow tasks (push) Blocked by required conditions
Some checks are pending
Cleanup Pull Requests / Clean up pull requests (push) Waiting to run
Coding Standards / PHP coding standards (push) Waiting to run
Coding Standards / JavaScript coding standards (push) Waiting to run
Coding Standards / Slack Notifications (push) Blocked by required conditions
Coding Standards / Failed workflow tasks (push) Blocked by required conditions
End-to-end Tests / Test with SCRIPT_DEBUG disabled (push) Waiting to run
End-to-end Tests / Test with SCRIPT_DEBUG enabled (push) Waiting to run
End-to-end Tests / Slack Notifications (push) Blocked by required conditions
End-to-end Tests / Failed workflow tasks (push) Blocked by required conditions
JavaScript Tests / QUnit Tests (push) Waiting to run
JavaScript Tests / Slack Notifications (push) Blocked by required conditions
JavaScript Tests / Failed workflow tasks (push) Blocked by required conditions
Performance Tests / Determine Matrix (push) Waiting to run
Performance Tests / ${{ matrix.multisite && 'Multisite' || 'Single Site' }} ${{ matrix.memcached && 'Memcached' || 'Default' }} (push) Blocked by required conditions
Performance Tests / Compare (push) Blocked by required conditions
Performance Tests / Slack Notifications (push) Blocked by required conditions
Performance Tests / Failed workflow tasks (push) Blocked by required conditions
PHP Compatibility / Check PHP compatibility (push) Waiting to run
PHP Compatibility / Slack Notifications (push) Blocked by required conditions
PHP Compatibility / Failed workflow tasks (push) Blocked by required conditions
PHPUnit Tests / PHP 7.2 (push) Waiting to run
PHPUnit Tests / PHP 7.3 (push) Waiting to run
PHPUnit Tests / PHP 7.4 (push) Waiting to run
PHPUnit Tests / PHP 8.0 (push) Waiting to run
PHPUnit Tests / PHP 8.1 (push) Waiting to run
PHPUnit Tests / PHP 8.2 (push) Waiting to run
PHPUnit Tests / PHP 8.3 (push) Waiting to run
PHPUnit Tests / PHP 8.4 (push) Waiting to run
PHPUnit Tests / html-api-html5lib-tests (push) Waiting to run
PHPUnit Tests / Slack Notifications (push) Blocked by required conditions
PHPUnit Tests / Failed workflow tasks (push) Blocked by required conditions
Test Build Processes / Core running from build (push) Waiting to run
Test Build Processes / Core running from src (push) Waiting to run
Test Build Processes / Gutenberg running from build (push) Waiting to run
Test Build Processes / Gutenberg running from src (push) Waiting to run
Test Build Processes / Slack Notifications (push) Blocked by required conditions
Test Build Processes / Failed workflow tasks (push) Blocked by required conditions
Upgrade Develop Version Tests / Build (push) Waiting to run
Upgrade Develop Version Tests / Upgrade from 6.5 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.6 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.7 (push) Blocked by required conditions
Upgrade Develop Version Tests / Slack Notifications (push) Blocked by required conditions
Upgrade Develop Version Tests / Failed workflow tasks (push) Blocked by required conditions
This facilitates debugging and better response / error handling, among other things. Props audrasjb, coquardcyr, dshanske, ironprogrammer, NathanAtmoz, pbearne, shulard, soulseekah. Fixes #38197. git-svn-id: https://develop.svn.wordpress.org/trunk@59818 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
66b98b92c3
commit
626d9af280
@ -2890,6 +2890,7 @@ function discover_pingback_server_uri( $url, $deprecated = '' ) {
|
||||
|
||||
$pingback_link_offset_dquote = strpos( $contents, $pingback_str_dquote );
|
||||
$pingback_link_offset_squote = strpos( $contents, $pingback_str_squote );
|
||||
|
||||
if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) {
|
||||
$quote = ( $pingback_link_offset_dquote ) ? '"' : '\'';
|
||||
$pingback_link_offset = ( '"' === $quote ) ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
|
||||
@ -3079,9 +3080,11 @@ function generic_ping( $post_id = 0 ) {
|
||||
*
|
||||
* @since 0.71
|
||||
* @since 4.7.0 `$post` can be a WP_Post object.
|
||||
* @since 6.8.0 Returns an array of pingback statuses indexed by link.
|
||||
*
|
||||
* @param string $content Post content to check for links. If empty will retrieve from post.
|
||||
* @param int|WP_Post $post Post ID or object.
|
||||
* @return array<string, bool> An array of pingback statuses indexed by link.
|
||||
*/
|
||||
function pingback( $content, $post ) {
|
||||
require_once ABSPATH . WPINC . '/class-IXR.php';
|
||||
@ -3093,7 +3096,7 @@ function pingback( $content, $post ) {
|
||||
$post = get_post( $post );
|
||||
|
||||
if ( ! $post ) {
|
||||
return;
|
||||
return array();
|
||||
}
|
||||
|
||||
$pung = get_pung( $post );
|
||||
@ -3108,6 +3111,7 @@ function pingback( $content, $post ) {
|
||||
*/
|
||||
$post_links_temp = wp_extract_urls( $content );
|
||||
|
||||
$ping_status = array();
|
||||
/*
|
||||
* Step 2.
|
||||
* Walking through the links array.
|
||||
@ -3179,11 +3183,18 @@ function pingback( $content, $post ) {
|
||||
// When set to true, this outputs debug messages by itself.
|
||||
$client->debug = false;
|
||||
|
||||
if ( $client->query( 'pingback.ping', $pagelinkedfrom, $pagelinkedto ) || ( isset( $client->error->code ) && 48 == $client->error->code ) ) { // Already registered.
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
91
tests/phpunit/tests/comment/pingback.php
Normal file
91
tests/phpunit/tests/comment/pingback.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group comment
|
||||
* @covers ::pingback
|
||||
*/
|
||||
class Tests_Comment_Pingback extends WP_UnitTestCase {
|
||||
|
||||
protected static $post_id;
|
||||
protected $response = array();
|
||||
|
||||
public function set_up() {
|
||||
parent::set_up();
|
||||
|
||||
add_filter( 'pre_http_request', array( $this, 'request_response' ) );
|
||||
}
|
||||
|
||||
public function tear_down() {
|
||||
remove_filter( 'pre_http_request', array( $this, 'request_response' ) );
|
||||
parent::tear_down();
|
||||
}
|
||||
|
||||
public function test_pingback() {
|
||||
$content = <<<HTML
|
||||
<a href="http://example.org">test</a>
|
||||
<a href="http://example1.org/test">test</a>
|
||||
<a href="http://example3.org/">test</a>
|
||||
HTML;
|
||||
|
||||
$body = <<<BODY
|
||||
<a rel="pingback" href="https://example1.org/test/pingback">test</a>
|
||||
BODY;
|
||||
|
||||
$this->response = array(
|
||||
'body' => $body,
|
||||
'response' => array( 'code' => 200 ),
|
||||
);
|
||||
|
||||
self::$post_id = self::factory()->post->create(
|
||||
array( 'post_content' => $content )
|
||||
);
|
||||
|
||||
$post = get_post( self::$post_id );
|
||||
$this->assertEquals( array( 'http://example1.org/test' => false ), pingback( $post->post_content, self::$post_id ) );
|
||||
}
|
||||
|
||||
public function test_pingback_no_ping_back() {
|
||||
$content = <<<HTML
|
||||
<a href="http://example.org">test</a>
|
||||
<a href="http://example1.org/test">test</a>
|
||||
<a href="http://example3.org/">test</a>
|
||||
HTML;
|
||||
|
||||
$body = <<<BODY
|
||||
<a href="https://example1.org/test">test</a>
|
||||
BODY;
|
||||
|
||||
$this->response = array(
|
||||
'body' => $body,
|
||||
'response' => array( 'code' => 200 ),
|
||||
);
|
||||
|
||||
self::$post_id = self::factory()->post->create(
|
||||
array( 'post_content' => $content )
|
||||
);
|
||||
|
||||
$post = get_post( self::$post_id );
|
||||
$this->assertEquals( array(), pingback( $post->post_content, self::$post_id ) );
|
||||
}
|
||||
|
||||
public function test_pingback_error_response() {
|
||||
$content = <<<HTML
|
||||
<a href="http://example.org">test</a>
|
||||
<a href="http://example1.org/test">test</a>
|
||||
<a href="http://example3.org/">test</a>
|
||||
HTML;
|
||||
|
||||
$this->response = new WP_Error();
|
||||
|
||||
self::$post_id = self::factory()->post->create(
|
||||
array( 'post_content' => $content )
|
||||
);
|
||||
|
||||
$post = get_post( self::$post_id );
|
||||
$this->assertEquals( array(), pingback( $post->post_content, self::$post_id ) );
|
||||
}
|
||||
|
||||
public function request_response() {
|
||||
return $this->response;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user