| @@ -12,23 +12,8 @@ | ||
| 12 | 12 | use Activitypub\Collection\Actors; |
| 13 | 13 | use Activitypub\Collection\Followers; |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Returns a users WebFinger "resource". | |
| 17 | - * | |
| 18 | - * @deprecated 7.1.0 Use {@see \Activitypub\Webfinger::get_user_resource} instead. | |
| 19 | - * | |
| 20 | - * @param int $user_id The user ID. | |
| 21 | - * | |
| 22 | - * @return string The User resource. | |
| 23 | - */ | |
| 24 | -function get_webfinger_resource( $user_id ) { | |
| 25 | - \_deprecated_function( __FUNCTION__, '7.1.0', 'Activitypub\Webfinger::get_user_resource' ); | |
| 26 | - | |
| 27 | - return Webfinger::get_user_resource( $user_id ); | |
| 28 | -} | |
| 29 | - | |
| 30 | -/** | |
| 31 | 16 | * Returns the followers of a given user. |
| 32 | 17 | * |
| 33 | 18 | * @param int $user_id The user ID. |
| 34 | 19 | * |
| @@ -62,9 +47,9 @@ | ||
| 62 | 47 | global $wp_rewrite; |
| 63 | 48 | |
| 64 | 49 | // Check if url has the same host. |
| 65 | 50 | $request_host = \wp_parse_url( $url, \PHP_URL_HOST ); |
| 66 | - if ( \wp_parse_url( \home_url(), \PHP_URL_HOST ) !== $request_host && get_option( 'activitypub_old_host' ) !== $request_host ) { | |
| 51 | + if ( \wp_parse_url( \home_url(), \PHP_URL_HOST ) !== $request_host && \get_option( 'activitypub_old_host' ) !== $request_host ) { | |
| 67 | 52 | return null; |
| 68 | 53 | } |
| 69 | 54 | |
| 70 | 55 | // First, check to see if there is an 'author=N' to match against. |
| @@ -102,17 +87,13 @@ | ||
| 102 | 87 | * |
| 103 | 88 | * @return boolean True if the user is enabled, false otherwise. |
| 104 | 89 | */ |
| 105 | 90 | function user_can_activitypub( $user_id ) { |
| 106 | - if ( ! is_numeric( $user_id ) ) { | |
| 91 | + if ( ! \is_numeric( $user_id ) ) { | |
| 107 | 92 | return false; |
| 108 | 93 | } |
| 109 | 94 | |
| 110 | 95 | switch ( $user_id ) { |
| 111 | - case Actors::APPLICATION_USER_ID: | |
| 112 | - $enabled = true; // Application user is always enabled. | |
| 113 | - break; | |
| 114 | - | |
| 115 | 96 | case Actors::BLOG_USER_ID: |
| 116 | 97 | $enabled = ! is_user_type_disabled( 'blog' ); |
| 117 | 98 | break; |
| 118 | 99 | |
| @@ -135,12 +116,43 @@ | ||
| 135 | 116 | * |
| 136 | 117 | * @param boolean $enabled True if the user is enabled, false otherwise. |
| 137 | 118 | * @param int $user_id The user ID. |
| 138 | 119 | */ |
| 139 | - return apply_filters( 'activitypub_user_can_activitypub', $enabled, $user_id ); | |
| 120 | + return \apply_filters( 'activitypub_user_can_activitypub', $enabled, $user_id ); | |
| 140 | 121 | } |
| 141 | 122 | |
| 142 | 123 | /** |
| 124 | + * Whether the current user is allowed to act on behalf of the blog actor. | |
| 125 | + * | |
| 126 | + * The blog actor is virtual (no `wp_users` row), so ownership and authoring | |
| 127 | + * checks against `BLOG_USER_ID = 0` cannot rely on identity equality. This | |
| 128 | + * helper centralizes the "can the current user post / read as the blog?" | |
| 129 | + * decision: administrators by default, filterable for integrations. | |
| 130 | + * | |
| 131 | + * @since 8.3.0 | |
| 132 | + * | |
| 133 | + * @return bool True if the current user can act as the blog actor. | |
| 134 | + */ | |
| 135 | +function user_can_act_as_blog() { | |
| 136 | + /** | |
| 137 | + * Filters whether the current user is allowed to act as the blog actor. | |
| 138 | + * | |
| 139 | + * Defaults to true for users with the `manage_options` capability (administrators). | |
| 140 | + * Filter to broaden the allow-list, for example to editors on multi-author sites. | |
| 141 | + * | |
| 142 | + * Security note: returning a static `true` (e.g. via `__return_true`) grants | |
| 143 | + * EVERY authenticated user the right to post as, read private outbox items of, | |
| 144 | + * and view stats for the blog actor. Always inspect the current user inside | |
| 145 | + * the callback (`current_user_can()`, role, allowlist) before returning `true`. | |
| 146 | + * | |
| 147 | + * @since 8.3.0 | |
| 148 | + * | |
| 149 | + * @param bool $can_act_as_blog Whether the current user can act as the blog actor. | |
| 150 | + */ | |
| 151 | + return (bool) \apply_filters( 'activitypub_user_can_act_as_blog', \current_user_can( 'manage_options' ) ); | |
| 152 | +} | |
| 153 | + | |
| 154 | +/** | |
| 143 | 155 | * Checks if a User-Type is disabled for ActivityPub. |
| 144 | 156 | * |
| 145 | 157 | * This function is used to check if the 'blog' or 'user' |
| 146 | 158 | * type is disabled for ActivityPub. |
| @@ -202,9 +214,9 @@ | ||
| 202 | 214 | * |
| 203 | 215 | * @param boolean $disabled True if the user type is disabled, false otherwise. |
| 204 | 216 | * @param string $type The User-Type. |
| 205 | 217 | */ |
| 206 | - return apply_filters( 'activitypub_is_user_type_disabled', $disabled, $type ); | |
| 218 | + return \apply_filters( 'activitypub_is_user_type_disabled', $disabled, $type ); | |
| 207 | 219 | } |
| 208 | 220 | |
| 209 | 221 | /** |
| 210 | 222 | * Check if the blog is in single-user mode. |