Skip to content
Merged
4 changes: 4 additions & 0 deletions .github/changelog/2085-from-description
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fix PHP 8.4 deprecation warnings by preventing null values from being passed to WordPress core functions
2 changes: 1 addition & 1 deletion includes/collection/class-actors.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ private static function prepare_custom_post_type( $actor ) {
'post_author' => 0,
'post_type' => self::POST_TYPE,
'post_content' => \wp_slash( $actor->to_json() ),
'post_excerpt' => \wp_kses( \wp_slash( $actor->get_summary() ), 'user_description' ),
'post_excerpt' => \wp_kses( \wp_slash( (string) $actor->get_summary() ), 'user_description' ),
'post_status' => 'publish',
'meta_input' => array(
'_activitypub_inbox' => $inbox,
Expand Down
66 changes: 34 additions & 32 deletions tests/includes/handler/class-test-announce.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ class Test_Announce extends \WP_UnitTestCase {
*/
public $user_id;

/**
* User URL.
*
* @var string
*/
public $user_url;

/**
* Post ID.
*
Expand All @@ -49,9 +42,7 @@ class Test_Announce extends \WP_UnitTestCase {
*/
public function set_up() {
parent::set_up();
$this->user_id = 1;
$authordata = \get_userdata( $this->user_id );
$this->user_url = $authordata->user_url;
$this->user_id = 1;

$this->post_id = \wp_insert_post(
array(
Expand All @@ -61,14 +52,14 @@ public function set_up() {
);
$this->post_permalink = \get_permalink( $this->post_id );

\add_filter( 'pre_get_remote_metadata_by_actor', array( get_called_class(), 'get_remote_metadata_by_actor' ), 0, 2 );
\add_filter( 'pre_get_remote_metadata_by_actor', array( $this, 'get_remote_metadata_by_actor' ), 0, 2 );
}

/**
* Tear down the test.
*/
public function tear_down() {
\remove_filter( 'pre_get_remote_metadata_by_actor', array( get_called_class(), 'get_remote_metadata_by_actor' ) );
\remove_filter( 'pre_get_remote_metadata_by_actor', array( $this, 'get_remote_metadata_by_actor' ) );
parent::tear_down();
}

Expand All @@ -79,7 +70,7 @@ public function tear_down() {
* @param string $actor The actor.
* @return array The metadata.
*/
public static function get_remote_metadata_by_actor( $value, $actor ) {
public function get_remote_metadata_by_actor( $value, $actor ) {
return array(
'name' => 'Example User',
'icon' => array(
Expand All @@ -95,14 +86,14 @@ public static function get_remote_metadata_by_actor( $value, $actor ) {
*
* @return array The test object.
*/
public function create_test_object() {
public static function create_test_object() {
return array(
'actor' => $this->user_url,
'actor' => 'https://example.com/user',
'type' => 'Announce',
'id' => 'https://example.com/id/' . microtime( true ),
'to' => array( $this->user_url ),
'to' => array( 'https://example.com/user' ),
'cc' => array( 'https://www.w3.org/ns/activitystreams#Public' ),
'object' => $this->post_permalink,
'object' => 'https://example.com/post/123',
);
}

Expand All @@ -112,7 +103,16 @@ public function create_test_object() {
* @covers ::handle_announce
*/
public function test_handle_announce() {
$object = $this->create_test_object();
$user_url = \get_userdata( $this->user_id )->user_url;

$object = array(
'actor' => $user_url,
'type' => 'Announce',
'id' => 'https://example.com/id/' . microtime( true ),
'to' => array( $user_url ),
'cc' => array( 'https://www.w3.org/ns/activitystreams#Public' ),
'object' => $this->post_permalink,
);

Announce::handle_announce( $object, $this->user_id );

Expand Down Expand Up @@ -149,16 +149,18 @@ public function test_handle_announces( $announce, $recursion, $message ) {
}

/**
* Test handle announce with invalid object.
* Test maybe save announce.
*
* @covers ::handle_announce
* @covers ::maybe_save_announce
*/
public function test_maybe_save_announce() {
$user_url = \get_userdata( $this->user_id )->user_url;

$activity = array(
'actor' => $this->user_url,
'actor' => $user_url,
'type' => 'Announce',
'id' => 'https://example.com/id/' . microtime( true ),
'to' => array( $this->user_url ),
'to' => array( $user_url ),
'object' => $this->post_permalink,
);

Expand All @@ -180,24 +182,24 @@ public function test_maybe_save_announce() {
*
* @return array The data provider.
*/
public function data_handle_announces() {
public static function data_handle_announces() {
return array(
array(
'announce' => $this->create_test_object(),
'announce' => self::create_test_object(),
'recursion' => 0,
'message' => 'Simple Announce of an URL.',
),
array(
'announce' => array(
'actor' => $this->user_url,
'actor' => 'https://example.com/user',
'type' => 'Announce',
'id' => 'https://example.com/id/' . microtime( true ),
'to' => array( $this->user_url ),
'to' => array( 'https://example.com/user' ),
'object' => array(
'actor' => $this->user_url,
'actor' => 'https://example.com/user',
'type' => 'Note',
'id' => $this->post_permalink,
'to' => array( $this->user_url ),
'id' => 'https://example.com/post/123',
'to' => array( 'https://example.com/user' ),
'content' => 'text',
),
),
Expand All @@ -206,11 +208,11 @@ public function data_handle_announces() {
),
array(
'announce' => array(
'actor' => $this->user_url,
'actor' => 'https://example.com/user',
'type' => 'Announce',
'id' => 'https://example.com/id/' . microtime( true ),
'to' => array( $this->user_url ),
'object' => $this->create_test_object(),
'to' => array( 'https://example.com/user' ),
'object' => self::create_test_object(),
),
'recursion' => 1,
'message' => 'Announce of an Announce-Object.',
Expand Down
1 change: 1 addition & 0 deletions tests/includes/handler/class-test-inbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function ( $response ) use ( &$filter_called ) {
'id' => 'https://example.com/object/1',
'type' => 'Note',
),
'actor' => 'https://example.com/actor/1',
);
$user_id = 1;
$type = 'Create';
Expand Down
Loading