From 6a0fc43a05e56308965854126be745d17aaf109e Mon Sep 17 00:00:00 2001 From: Matt Wiebe Date: Thu, 18 May 2023 19:30:08 -0500 Subject: [PATCH 1/3] Set `ACTIVITYPUB_REST_NAMESPACE` outside of `init` Needed to prevent activation errors. --- activitypub.php | 4 ++-- includes/rest/class-outbox.php | 3 +++ includes/rest/class-webfinger.php | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/activitypub.php b/activitypub.php index 5b19dce..3f582ea 100644 --- a/activitypub.php +++ b/activitypub.php @@ -15,6 +15,8 @@ namespace Activitypub; +\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' ); + /** * Initialize plugin */ @@ -25,8 +27,6 @@ function init() { \defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|(?<=

)|(?<=
)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))' ); \defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' ); \defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "[ap_title]\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" ); - \defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' ); - \define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); \define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); \define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) ); diff --git a/includes/rest/class-outbox.php b/includes/rest/class-outbox.php index abffbe9..087c0ef 100644 --- a/includes/rest/class-outbox.php +++ b/includes/rest/class-outbox.php @@ -80,6 +80,8 @@ class Outbox { // phpcs:ignore $json->totalItems = 0; + // We can query this more directly based on the supplied post types. + // And cache these counts and invalidate them on publish_post. foreach ( $post_types as $post_type ) { $count_posts = \wp_count_posts( $post_type ); $json->totalItems += \intval( $count_posts->publish ); // phpcs:ignore @@ -142,6 +144,7 @@ class Outbox { 'required' => true, 'type' => 'integer', 'validate_callback' => function( $param, $request, $key ) { + // this is probably ok on multisite still? return user_can( $param, 'publish_posts' ); }, ); diff --git a/includes/rest/class-webfinger.php b/includes/rest/class-webfinger.php index f75a3f7..e7c00fa 100644 --- a/includes/rest/class-webfinger.php +++ b/includes/rest/class-webfinger.php @@ -62,6 +62,7 @@ class Webfinger { } $user = \get_user_by( 'login', \esc_sql( $resource_identifier ) ); + /// YIKES NOPE NOPE NOT ON DOTCOM! if ( ! $user || ! \user_can( $user, 'publish_posts' ) ) { return new WP_Error( 'activitypub_user_not_found', \__( 'User not found', 'activitypub' ), array( 'status' => 404 ) ); From d7d6ebbc1fd231ee4d470a2e23d3ad49eaa681e6 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Fri, 19 May 2023 11:43:54 +0200 Subject: [PATCH 2/3] remove comments @mattwiebe maybe you can add them as issues --- includes/rest/class-outbox.php | 1 - includes/rest/class-webfinger.php | 1 - 2 files changed, 2 deletions(-) diff --git a/includes/rest/class-outbox.php b/includes/rest/class-outbox.php index 087c0ef..9fff8c7 100644 --- a/includes/rest/class-outbox.php +++ b/includes/rest/class-outbox.php @@ -144,7 +144,6 @@ class Outbox { 'required' => true, 'type' => 'integer', 'validate_callback' => function( $param, $request, $key ) { - // this is probably ok on multisite still? return user_can( $param, 'publish_posts' ); }, ); diff --git a/includes/rest/class-webfinger.php b/includes/rest/class-webfinger.php index e7c00fa..f75a3f7 100644 --- a/includes/rest/class-webfinger.php +++ b/includes/rest/class-webfinger.php @@ -62,7 +62,6 @@ class Webfinger { } $user = \get_user_by( 'login', \esc_sql( $resource_identifier ) ); - /// YIKES NOPE NOPE NOT ON DOTCOM! if ( ! $user || ! \user_can( $user, 'publish_posts' ) ) { return new WP_Error( 'activitypub_user_not_found', \__( 'User not found', 'activitypub' ), array( 'status' => 404 ) ); From 70c3b3fd517c3dbb7064e746e792b004d920182e Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Fri, 19 May 2023 11:45:12 +0200 Subject: [PATCH 3/3] remove comments --- includes/rest/class-outbox.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/rest/class-outbox.php b/includes/rest/class-outbox.php index 9fff8c7..abffbe9 100644 --- a/includes/rest/class-outbox.php +++ b/includes/rest/class-outbox.php @@ -80,8 +80,6 @@ class Outbox { // phpcs:ignore $json->totalItems = 0; - // We can query this more directly based on the supplied post types. - // And cache these counts and invalidate them on publish_post. foreach ( $post_types as $post_type ) { $count_posts = \wp_count_posts( $post_type ); $json->totalItems += \intval( $count_posts->publish ); // phpcs:ignore