Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/changelog/2507-from-description
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Maintain consistent return values in Create handler.
22 changes: 13 additions & 9 deletions includes/handler/class-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ public static function handle_create( $activity, $user_ids, $activity_object = n
* @param int[] $user_ids The ids of the local blog-users.
* @param \Activitypub\Activity\Activity $activity_object Optional. The activity object. Default null.
*
* @return \WP_Comment|\WP_Error|false The created comment, WP_Error on failure, false if not processed.
* @return \WP_Comment|\WP_Error|false The created comment, WP_Error on failure, false if already exists or not processed.
*/
public static function create_interaction( $activity, $user_ids, $activity_object = null ) {
$check_dupe = object_id_to_comment( $activity['object']['id'] );
$existing_comment = object_id_to_comment( $activity['object']['id'] );

// If comment exists, call update action.
if ( $check_dupe ) {
return Update::handle_update( $activity, (array) $user_ids, $activity_object );
if ( $existing_comment ) {
Update::handle_update( $activity, (array) $user_ids, $activity_object );

return false;
}

if ( is_self_ping( $activity['object']['id'] ) ) {
Expand All @@ -101,14 +103,16 @@ public static function create_interaction( $activity, $user_ids, $activity_objec
* @param int[] $user_ids The ids of the local blog-users.
* @param \Activitypub\Activity\Activity $activity_object Optional. The activity object. Default null.
*
* @return \WP_Post|\WP_Error|false The post on success or WP_Error on failure.
* @return \WP_Post|\WP_Error|false The post on success, WP_Error on failure, false if already exists.
*/
public static function create_post( $activity, $user_ids, $activity_object = null ) {
$check_dupe = Posts::get_by_guid( $activity['object']['id'] );
$existing_post = Posts::get_by_guid( $activity['object']['id'] );

// If comment exists, call update action.
if ( ! \is_wp_error( $check_dupe ) ) {
return Update::handle_update( $activity, (array) $user_ids, $activity_object );
// If post exists, call update action.
if ( $existing_post instanceof \WP_Post ) {
Update::handle_update( $activity, (array) $user_ids, $activity_object );

return false;
}

return Posts::add( $activity, $user_ids );
Expand Down