| @@ -12,8 +12,23 @@ | ||
| 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 | +/** | |
| 16 | 31 | * Returns the followers of a given user. |
| 17 | 32 | * |
| 18 | 33 | * @param int $user_id The user ID. |
| 19 | 34 | * |
| @@ -47,9 +62,9 @@ | ||
| 47 | 62 | global $wp_rewrite; |
| 48 | 63 | |
| 49 | 64 | // Check if url has the same host. |
| 50 | 65 | $request_host = \wp_parse_url( $url, \PHP_URL_HOST ); |
| 51 | - if ( \wp_parse_url( \home_url(), \PHP_URL_HOST ) !== $request_host && \get_option( 'activitypub_old_host' ) !== $request_host ) { | |
| 66 | + if ( \wp_parse_url( \home_url(), \PHP_URL_HOST ) !== $request_host && get_option( 'activitypub_old_host' ) !== $request_host ) { | |
| 52 | 67 | return null; |
| 53 | 68 | } |
| 54 | 69 | |
| 55 | 70 | // First, check to see if there is an 'author=N' to match against. |
| @@ -87,13 +102,17 @@ | ||
| 87 | 102 | * |
| 88 | 103 | * @return boolean True if the user is enabled, false otherwise. |
| 89 | 104 | */ |
| 90 | 105 | function user_can_activitypub( $user_id ) { |
| 91 | - if ( ! \is_numeric( $user_id ) ) { | |
| 106 | + if ( ! is_numeric( $user_id ) ) { | |
| 92 | 107 | return false; |
| 93 | 108 | } |
| 94 | 109 | |
| 95 | 110 | switch ( $user_id ) { |
| 111 | + case Actors::APPLICATION_USER_ID: | |
| 112 | + $enabled = true; // Application user is always enabled. | |
| 113 | + break; | |
| 114 | + | |
| 96 | 115 | case Actors::BLOG_USER_ID: |
| 97 | 116 | $enabled = ! is_user_type_disabled( 'blog' ); |
| 98 | 117 | break; |
| 99 | 118 | |
| @@ -116,43 +135,12 @@ | ||
| 116 | 135 | * |
| 117 | 136 | * @param boolean $enabled True if the user is enabled, false otherwise. |
| 118 | 137 | * @param int $user_id The user ID. |
| 119 | 138 | */ |
| 120 | - return \apply_filters( 'activitypub_user_can_activitypub', $enabled, $user_id ); | |
| 139 | + return apply_filters( 'activitypub_user_can_activitypub', $enabled, $user_id ); | |
| 121 | 140 | } |
| 122 | 141 | |
| 123 | 142 | /** |
| 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 | -/** | |
| 155 | 143 | * Checks if a User-Type is disabled for ActivityPub. |
| 156 | 144 | * |
| 157 | 145 | * This function is used to check if the 'blog' or 'user' |
| 158 | 146 | * type is disabled for ActivityPub. |
| @@ -214,9 +202,9 @@ | ||
| 214 | 202 | * |
| 215 | 203 | * @param boolean $disabled True if the user type is disabled, false otherwise. |
| 216 | 204 | * @param string $type The User-Type. |
| 217 | 205 | */ |
| 218 | - return \apply_filters( 'activitypub_is_user_type_disabled', $disabled, $type ); | |
| 206 | + return apply_filters( 'activitypub_is_user_type_disabled', $disabled, $type ); | |
| 219 | 207 | } |
| 220 | 208 | |
| 221 | 209 | /** |
| 222 | 210 | * Check if the blog is in single-user mode. |