| @@ -7,12 +7,11 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace Activitypub\Collection; |
| 9 | 9 | |
| 10 | 10 | use Activitypub\Activity\Actor; |
| 11 | -use Activitypub\Application; | |
| 11 | +use Activitypub\Model\Application; | |
| 12 | 12 | use Activitypub\Model\Blog; |
| 13 | 13 | use Activitypub\Model\User; |
| 14 | -use Activitypub\Signature; | |
| 15 | 14 | |
| 16 | 15 | use function Activitypub\is_user_type_disabled; |
| 17 | 16 | use function Activitypub\normalize_host; |
| 18 | 17 | use function Activitypub\normalize_url; |
| @@ -33,12 +32,10 @@ | ||
| 33 | 32 | */ |
| 34 | 33 | const BLOG_USER_ID = 0; |
| 35 | 34 | |
| 36 | 35 | /** |
| 37 | - * The ID of the former Application user. | |
| 36 | + * The ID of the Application User. | |
| 38 | 37 | * |
| 39 | - * @deprecated 9.1.0 The Application is no longer a user-like actor, see {@see \Activitypub\Application}. Retained for backward compatibility and legacy data handling. | |
| 40 | - * | |
| 41 | 38 | * @var int |
| 42 | 39 | */ |
| 43 | 40 | const APPLICATION_USER_ID = -1; |
| 44 | 41 | |
| @@ -49,29 +46,12 @@ | ||
| 49 | 46 | * |
| 50 | 47 | * @return Actor|User|Blog|Application|\WP_Error Actor object or WP_Error if not found or not permitted. |
| 51 | 48 | */ |
| 52 | 49 | public static function get_by_id( $user_id ) { |
| 53 | - if ( \is_numeric( $user_id ) ) { | |
| 50 | + if ( is_numeric( $user_id ) ) { | |
| 54 | 51 | $user_id = (int) $user_id; |
| 55 | 52 | } |
| 56 | 53 | |
| 57 | - /** | |
| 58 | - * Filter the actor before resolving by ID. | |
| 59 | - * | |
| 60 | - * Allows third-party plugins to register custom virtual actors | |
| 61 | - * resolved by ID, mirroring the `activitypub_pre_get_by_username` | |
| 62 | - * filter for username lookups. | |
| 63 | - * | |
| 64 | - * @since 8.1.0 | |
| 65 | - * | |
| 66 | - * @param null $pre The pre-existing value. | |
| 67 | - * @param int $user_id The user ID. | |
| 68 | - */ | |
| 69 | - $pre = \apply_filters( 'activitypub_pre_get_by_id', null, $user_id ); | |
| 70 | - if ( null !== $pre ) { | |
| 71 | - return $pre; | |
| 72 | - } | |
| 73 | - | |
| 74 | 54 | if ( ! user_can_activitypub( $user_id ) ) { |
| 75 | 55 | return new \WP_Error( |
| 76 | 56 | 'activitypub_user_not_found', |
| 77 | 57 | \__( 'Actor not found', 'activitypub' ), |
| @@ -81,8 +61,10 @@ | ||
| 81 | 61 | |
| 82 | 62 | switch ( $user_id ) { |
| 83 | 63 | case self::BLOG_USER_ID: |
| 84 | 64 | return new Blog(); |
| 65 | + case self::APPLICATION_USER_ID: | |
| 66 | + return new Application(); | |
| 85 | 67 | default: |
| 86 | 68 | return User::from_wp_user( $user_id ); |
| 87 | 69 | } |
| 88 | 70 | } |
| @@ -100,9 +82,9 @@ | ||
| 100 | 82 | * |
| 101 | 83 | * @param null $pre The pre-existing value. |
| 102 | 84 | * @param string $username The username. |
| 103 | 85 | */ |
| 104 | - $pre = \apply_filters( 'activitypub_pre_get_by_username', null, $username ); | |
| 86 | + $pre = apply_filters( 'activitypub_pre_get_by_username', null, $username ); | |
| 105 | 87 | if ( null !== $pre ) { |
| 106 | 88 | return $pre; |
| 107 | 89 | } |
| 108 | 90 | |
| @@ -137,21 +119,11 @@ | ||
| 137 | 119 | |
| 138 | 120 | return self::BLOG_USER_ID; |
| 139 | 121 | } |
| 140 | 122 | |
| 141 | - /* | |
| 142 | - * The 'application' identifier is reserved for the signing-only Application | |
| 143 | - * actor, which is served only through the dedicated /application endpoint. | |
| 144 | - * Never resolve it to a regular user, even on sites that happen to have a | |
| 145 | - * user named "application". Compare lowercased: the user lookups below are | |
| 146 | - * case-insensitive, so the reservation has to be too. | |
| 147 | - */ | |
| 148 | - if ( Application::USERNAME === \strtolower( $username ) ) { | |
| 149 | - return new \WP_Error( | |
| 150 | - 'activitypub_user_not_found', | |
| 151 | - \__( 'Actor not found', 'activitypub' ), | |
| 152 | - array( 'status' => 404 ) | |
| 153 | - ); | |
| 123 | + // Check for application user. | |
| 124 | + if ( 'application' === $username ) { | |
| 125 | + return self::APPLICATION_USER_ID; | |
| 154 | 126 | } |
| 155 | 127 | |
| 156 | 128 | // Check for 'activitypub_username' meta. |
| 157 | 129 | $user = new \WP_User_Query( |
| @@ -175,9 +147,9 @@ | ||
| 175 | 147 | if ( $user->get_results() ) { |
| 176 | 148 | return \current( $user->get_results() ); |
| 177 | 149 | } |
| 178 | 150 | |
| 179 | - $username = \str_replace( array( '*', '%' ), '', $username ); | |
| 151 | + $username = str_replace( array( '*', '%' ), '', $username ); | |
| 180 | 152 | |
| 181 | 153 | // Check for login or nicename. |
| 182 | 154 | $user = new \WP_User_Query( |
| 183 | 155 | array( |
| @@ -237,9 +209,9 @@ | ||
| 237 | 209 | |
| 238 | 210 | $scheme = 'acct'; |
| 239 | 211 | $match = array(); |
| 240 | 212 | // Try to extract the scheme and the host. |
| 241 | - if ( \preg_match( '/^([a-zA-Z^:]+):(.*)$/i', $uri, $match ) ) { | |
| 213 | + if ( preg_match( '/^([a-zA-Z^:]+):(.*)$/i', $uri, $match ) ) { | |
| 242 | 214 | // Extract the scheme. |
| 243 | 215 | $scheme = \esc_attr( $match[1] ); |
| 244 | 216 | } |
| 245 | 217 | |
| @@ -261,9 +233,9 @@ | ||
| 261 | 233 | } |
| 262 | 234 | |
| 263 | 235 | $resource_path = \trim( $resource_path, '/' ); |
| 264 | 236 | |
| 265 | - if ( \str_starts_with( $resource_path, '@' ) ) { | |
| 237 | + if ( str_starts_with( $resource_path, '@' ) ) { | |
| 266 | 238 | $identifier = \str_replace( '@', '', $resource_path ); |
| 267 | 239 | $identifier = \trim( $identifier, '/' ); |
| 268 | 240 | |
| 269 | 241 | return self::get_id_by_username( $identifier ); |
| @@ -280,10 +252,10 @@ | ||
| 280 | 252 | // Check for http(s)://blog.example.com/. |
| 281 | 253 | $normalized_uri = normalize_url( $uri ); |
| 282 | 254 | |
| 283 | 255 | if ( |
| 284 | - normalize_url( \site_url() ) === $normalized_uri || | |
| 285 | - normalize_url( \home_url() ) === $normalized_uri | |
| 256 | + normalize_url( site_url() ) === $normalized_uri || | |
| 257 | + normalize_url( home_url() ) === $normalized_uri | |
| 286 | 258 | ) { |
| 287 | 259 | return self::BLOG_USER_ID; |
| 288 | 260 | } |
| 289 | 261 | |
| @@ -298,9 +270,9 @@ | ||
| 298 | 270 | $identifier = \substr( $uri, 0, \strrpos( $uri, '@' ) ); |
| 299 | 271 | $host = normalize_host( \substr( \strrchr( $uri, '@' ), 1 ) ); |
| 300 | 272 | $blog_host = normalize_host( \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) ); |
| 301 | 273 | |
| 302 | - if ( $blog_host !== $host && normalize_host( \get_option( 'activitypub_old_host' ) ) !== $host ) { | |
| 274 | + if ( $blog_host !== $host && get_option( 'activitypub_old_host' ) !== $host ) { | |
| 303 | 275 | return new \WP_Error( |
| 304 | 276 | 'activitypub_wrong_host', |
| 305 | 277 | \__( 'Resource host does not match blog host', 'activitypub' ), |
| 306 | 278 | array( 'status' => 404 ) |
| @@ -307,9 +279,9 @@ | ||
| 307 | 279 | ); |
| 308 | 280 | } |
| 309 | 281 | |
| 310 | 282 | // Prepare wildcards https://github.com/mastodon/mastodon/issues/22213. |
| 311 | - if ( \in_array( $identifier, array( '_', '*', '' ), true ) ) { | |
| 283 | + if ( in_array( $identifier, array( '_', '*', '' ), true ) ) { | |
| 312 | 284 | return self::BLOG_USER_ID; |
| 313 | 285 | } |
| 314 | 286 | |
| 315 | 287 | return self::get_id_by_username( $identifier ); |
| @@ -345,17 +317,17 @@ | ||
| 345 | 317 | * |
| 346 | 318 | * @return int|\WP_Error Actor id or WP_Error if not found. |
| 347 | 319 | */ |
| 348 | 320 | public static function get_id_by_various( $id ) { |
| 349 | - if ( \is_numeric( $id ) ) { | |
| 321 | + if ( is_numeric( $id ) ) { | |
| 350 | 322 | $id = (int) $id; |
| 351 | 323 | } elseif ( |
| 352 | 324 | // Is URL. |
| 353 | - \filter_var( $id, FILTER_VALIDATE_URL ) || | |
| 325 | + filter_var( $id, FILTER_VALIDATE_URL ) || | |
| 354 | 326 | // Is acct. |
| 355 | - \str_starts_with( $id, 'acct:' ) || | |
| 327 | + str_starts_with( $id, 'acct:' ) || | |
| 356 | 328 | // Is email. |
| 357 | - \filter_var( $id, FILTER_VALIDATE_EMAIL ) | |
| 329 | + filter_var( $id, FILTER_VALIDATE_EMAIL ) | |
| 358 | 330 | ) { |
| 359 | 331 | $id = self::get_id_by_resource( $id ); |
| 360 | 332 | } else { |
| 361 | 333 | $id = self::get_id_by_username( $id ); |
| @@ -395,56 +367,8 @@ | ||
| 395 | 367 | return $return; |
| 396 | 368 | } |
| 397 | 369 | |
| 398 | 370 | /** |
| 399 | - * Search local actors by name or username. | |
| 400 | - * | |
| 401 | - * Backs the actor autocomplete endpoint. Matches the search term against the WordPress user's | |
| 402 | - * login, nicename, and display name; the Blog actor is included when its name or identifier | |
| 403 | - * matches. Disabled actor types are excluded, mirroring get_collection()/get_all(). | |
| 404 | - * | |
| 405 | - * @since 9.1.0 | |
| 406 | - * | |
| 407 | - * @param string $query The search term. | |
| 408 | - * @param int $number Optional. Maximum number of actors to return. Default 10. | |
| 409 | - * | |
| 410 | - * @return Actor[] The matching local actor objects. | |
| 411 | - */ | |
| 412 | - public static function search( $query, $number = 10 ) { | |
| 413 | - $actors = array(); | |
| 414 | - | |
| 415 | - if ( ! is_user_type_disabled( 'blog' ) ) { | |
| 416 | - $blog = new Blog(); | |
| 417 | - if ( false !== \stripos( $blog->get_name(), $query ) || false !== \stripos( (string) $blog->get_preferred_username(), $query ) ) { | |
| 418 | - $actors[] = $blog; | |
| 419 | - } | |
| 420 | - } | |
| 421 | - | |
| 422 | - // Only query as many users as the Blog actor left room for, so a match is never fetched then trimmed. | |
| 423 | - $remaining = $number - \count( $actors ); | |
| 424 | - | |
| 425 | - if ( $remaining > 0 && ! is_user_type_disabled( 'user' ) ) { | |
| 426 | - $users = \get_users( | |
| 427 | - array( | |
| 428 | - 'capability__in' => array( 'activitypub' ), | |
| 429 | - 'search' => '*' . $query . '*', | |
| 430 | - 'search_columns' => array( 'user_login', 'user_nicename', 'display_name' ), | |
| 431 | - 'number' => $remaining, | |
| 432 | - ) | |
| 433 | - ); | |
| 434 | - | |
| 435 | - foreach ( $users as $user ) { | |
| 436 | - $actor = User::from_wp_user( $user->ID ); | |
| 437 | - if ( ! \is_wp_error( $actor ) ) { | |
| 438 | - $actors[] = $actor; | |
| 439 | - } | |
| 440 | - } | |
| 441 | - } | |
| 442 | - | |
| 443 | - return $actors; | |
| 444 | - } | |
| 445 | - | |
| 446 | - /** | |
| 447 | 371 | * Get all active actors, including the Blog actor if enabled. |
| 448 | 372 | * |
| 449 | 373 | * @return int[] Array of User and Blog actor IDs. |
| 450 | 374 | */ |
| @@ -464,9 +388,9 @@ | ||
| 464 | 388 | if ( ! is_user_type_disabled( 'blog' ) ) { |
| 465 | 389 | $user_ids[] = self::BLOG_USER_ID; |
| 466 | 390 | } |
| 467 | 391 | |
| 468 | - return \array_map( 'intval', $user_ids ); | |
| 392 | + return array_map( 'intval', $user_ids ); | |
| 469 | 393 | } |
| 470 | 394 | |
| 471 | 395 | /** |
| 472 | 396 | * Get all active actors, including the Blog actor if enabled. |
| @@ -475,12 +399,12 @@ | ||
| 475 | 399 | */ |
| 476 | 400 | public static function get_all() { |
| 477 | 401 | $user_ids = self::get_all_ids(); |
| 478 | 402 | |
| 479 | - $actors = \array_map( array( self::class, 'get_by_id' ), $user_ids ); | |
| 403 | + $actors = array_map( array( self::class, 'get_by_id' ), $user_ids ); | |
| 480 | 404 | |
| 481 | 405 | // Filter out any WP_Error instances. |
| 482 | - return \array_filter( | |
| 406 | + return array_filter( | |
| 483 | 407 | $actors, |
| 484 | 408 | static function ( $actor ) { |
| 485 | 409 | return ! \is_wp_error( $actor ); |
| 486 | 410 | } |
| @@ -491,13 +415,17 @@ | ||
| 491 | 415 | * Returns the actor type based on the user ID. |
| 492 | 416 | * |
| 493 | 417 | * @param int $user_id The user ID to check. |
| 494 | 418 | * |
| 495 | - * @return string Actor type: 'user' or 'blog'. | |
| 419 | + * @return string Actor type: 'user', 'blog', or 'application'. | |
| 496 | 420 | */ |
| 497 | 421 | public static function get_type_by_id( $user_id ) { |
| 498 | 422 | $user_id = (int) $user_id; |
| 499 | 423 | |
| 424 | + if ( self::APPLICATION_USER_ID === $user_id ) { | |
| 425 | + return 'application'; | |
| 426 | + } | |
| 427 | + | |
| 500 | 428 | if ( self::BLOG_USER_ID === $user_id ) { |
| 501 | 429 | return 'blog'; |
| 502 | 430 | } |
| 503 | 431 | |
| @@ -507,15 +435,15 @@ | ||
| 507 | 435 | /** |
| 508 | 436 | * Return the public key for a given actor. |
| 509 | 437 | * |
| 510 | 438 | * @param int $user_id The WordPress User ID. |
| 511 | - * @param bool $force Deprecated. Keys are never rotated; new pairs are only generated when none is stored. | |
| 439 | + * @param bool $force Optional. Force the generation of a new key pair. Default false. | |
| 512 | 440 | * |
| 513 | 441 | * @return string The public key. |
| 514 | 442 | */ |
| 515 | 443 | public static function get_public_key( $user_id, $force = false ) { |
| 516 | 444 | if ( $force ) { |
| 517 | - \_deprecated_argument( __METHOD__, '9.1.0', \esc_html__( 'Keys are never rotated; new pairs are only generated when none is stored.', 'activitypub' ) ); | |
| 445 | + self::generate_key_pair( $user_id ); | |
| 518 | 446 | } |
| 519 | 447 | |
| 520 | 448 | $key_pair = self::get_keypair( $user_id ); |
| 521 | 449 | |
| @@ -525,15 +453,15 @@ | ||
| 525 | 453 | /** |
| 526 | 454 | * Return the private key for a given actor. |
| 527 | 455 | * |
| 528 | 456 | * @param int $user_id The WordPress User ID. |
| 529 | - * @param bool $force Deprecated. Keys are never rotated; new pairs are only generated when none is stored. | |
| 457 | + * @param bool $force Optional. Force the generation of a new key pair. Default false. | |
| 530 | 458 | * |
| 531 | 459 | * @return string The private key. |
| 532 | 460 | */ |
| 533 | 461 | public static function get_private_key( $user_id, $force = false ) { |
| 534 | 462 | if ( $force ) { |
| 535 | - \_deprecated_argument( __METHOD__, '9.1.0', \esc_html__( 'Keys are never rotated; new pairs are only generated when none is stored.', 'activitypub' ) ); | |
| 463 | + self::generate_key_pair( $user_id ); | |
| 536 | 464 | } |
| 537 | 465 | |
| 538 | 466 | $key_pair = self::get_keypair( $user_id ); |
| 539 | 467 | |
| @@ -547,14 +475,70 @@ | ||
| 547 | 475 | * |
| 548 | 476 | * @return array The key pair. |
| 549 | 477 | */ |
| 550 | 478 | public static function get_keypair( $user_id ) { |
| 551 | - return Signature::get_key_pair( | |
| 552 | - self::get_signature_options_key( $user_id ), | |
| 553 | - function () use ( $user_id ) { | |
| 554 | - return self::check_legacy_key_pair( $user_id ); | |
| 555 | - } | |
| 479 | + $option_key = self::get_signature_options_key( $user_id ); | |
| 480 | + $key_pair = \get_option( $option_key ); | |
| 481 | + | |
| 482 | + if ( ! $key_pair ) { | |
| 483 | + $key_pair = self::generate_key_pair( $user_id ); | |
| 484 | + } | |
| 485 | + | |
| 486 | + return $key_pair; | |
| 487 | + } | |
| 488 | + | |
| 489 | + /** | |
| 490 | + * Generates the pair of keys. | |
| 491 | + * | |
| 492 | + * @param int $user_id The WordPress User ID. | |
| 493 | + * | |
| 494 | + * @return array The key pair. | |
| 495 | + */ | |
| 496 | + protected static function generate_key_pair( $user_id ) { | |
| 497 | + $option_key = self::get_signature_options_key( $user_id ); | |
| 498 | + $key_pair = self::check_legacy_key_pair( $user_id ); | |
| 499 | + | |
| 500 | + if ( $key_pair ) { | |
| 501 | + \add_option( $option_key, $key_pair ); | |
| 502 | + | |
| 503 | + return $key_pair; | |
| 504 | + } | |
| 505 | + | |
| 506 | + $config = array( | |
| 507 | + 'digest_alg' => 'sha512', | |
| 508 | + 'private_key_bits' => 2048, | |
| 509 | + 'private_key_type' => \OPENSSL_KEYTYPE_RSA, | |
| 556 | 510 | ); |
| 511 | + | |
| 512 | + $key = \openssl_pkey_new( $config ); | |
| 513 | + $private_key = null; | |
| 514 | + $detail = array(); | |
| 515 | + if ( $key ) { | |
| 516 | + \openssl_pkey_export( $key, $private_key ); | |
| 517 | + | |
| 518 | + $detail = \openssl_pkey_get_details( $key ); | |
| 519 | + } | |
| 520 | + | |
| 521 | + // Check if keys are valid. | |
| 522 | + if ( | |
| 523 | + empty( $private_key ) || ! is_string( $private_key ) || | |
| 524 | + ! isset( $detail['key'] ) || ! is_string( $detail['key'] ) | |
| 525 | + ) { | |
| 526 | + return array( | |
| 527 | + 'private_key' => null, | |
| 528 | + 'public_key' => null, | |
| 529 | + ); | |
| 530 | + } | |
| 531 | + | |
| 532 | + $key_pair = array( | |
| 533 | + 'private_key' => $private_key, | |
| 534 | + 'public_key' => $detail['key'], | |
| 535 | + ); | |
| 536 | + | |
| 537 | + // Persist keys. | |
| 538 | + \add_option( $option_key, $key_pair ); | |
| 539 | + | |
| 540 | + return $key_pair; | |
| 557 | 541 | } |
| 558 | 542 | |
| 559 | 543 | /** |
| 560 | 544 | * Return the option key for a given user. |
| @@ -585,8 +569,12 @@ | ||
| 585 | 569 | case 0: |
| 586 | 570 | $public_key = \get_option( 'activitypub_blog_user_public_key' ); |
| 587 | 571 | $private_key = \get_option( 'activitypub_blog_user_private_key' ); |
| 588 | 572 | break; |
| 573 | + case -1: | |
| 574 | + $public_key = \get_option( 'activitypub_application_user_public_key' ); | |
| 575 | + $private_key = \get_option( 'activitypub_application_user_private_key' ); | |
| 576 | + break; | |
| 589 | 577 | default: |
| 590 | 578 | $public_key = \get_user_meta( $user_id, 'magic_sig_public_key', true ); |
| 591 | 579 | $private_key = \get_user_meta( $user_id, 'magic_sig_private_key', true ); |
| 592 | 580 | break; |
| @@ -591,9 +579,9 @@ | ||
| 591 | 579 | $private_key = \get_user_meta( $user_id, 'magic_sig_private_key', true ); |
| 592 | 580 | break; |
| 593 | 581 | } |
| 594 | 582 | |
| 595 | - if ( ! empty( $public_key ) && \is_string( $public_key ) && ! empty( $private_key ) && \is_string( $private_key ) ) { | |
| 583 | + if ( ! empty( $public_key ) && is_string( $public_key ) && ! empty( $private_key ) && is_string( $private_key ) ) { | |
| 596 | 584 | return array( |
| 597 | 585 | 'private_key' => $private_key, |
| 598 | 586 | 'public_key' => $public_key, |
| 599 | 587 | ); |
| @@ -599,8 +587,236 @@ | ||
| 599 | 587 | ); |
| 600 | 588 | } |
| 601 | 589 | |
| 602 | 590 | return false; |
| 591 | + } | |
| 592 | + | |
| 593 | + /** | |
| 594 | + * Returns all Inboxes for all known remote Actors. | |
| 595 | + * | |
| 596 | + * @deprecated 7.4.0 Use {@see Remote_Actors::get_inboxes()} | |
| 597 | + * | |
| 598 | + * @return array The list of Inboxes. | |
| 599 | + */ | |
| 600 | + public static function get_inboxes() { | |
| 601 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::get_inboxes' ); | |
| 602 | + return Remote_Actors::get_inboxes(); | |
| 603 | + } | |
| 604 | + | |
| 605 | + /** | |
| 606 | + * Upsert (insert or update) a remote actor as a custom post type. | |
| 607 | + * | |
| 608 | + * @deprecated 7.4.0 Use {@see Remote_Actors::upsert()} | |
| 609 | + * | |
| 610 | + * @param array|Actor $actor ActivityPub actor object (array or actor, must include 'id'). | |
| 611 | + * | |
| 612 | + * @return int|\WP_Error Post ID on success, WP_Error on failure. | |
| 613 | + */ | |
| 614 | + public static function upsert( $actor ) { | |
| 615 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::upsert' ); | |
| 616 | + return Remote_Actors::upsert( $actor ); | |
| 617 | + } | |
| 618 | + | |
| 619 | + /** | |
| 620 | + * Create a remote actor as a custom post type. | |
| 621 | + * | |
| 622 | + * @deprecated 7.4.0 Use {@see Remote_Actors::create()} | |
| 623 | + * | |
| 624 | + * @param array|Actor $actor ActivityPub actor object (array or Actor, must include 'id'). | |
| 625 | + * | |
| 626 | + * @return int|\WP_Error Post ID on success, WP_Error on failure. | |
| 627 | + */ | |
| 628 | + public static function create( $actor ) { | |
| 629 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::create' ); | |
| 630 | + return Remote_Actors::create( $actor ); | |
| 631 | + } | |
| 632 | + | |
| 633 | + /** | |
| 634 | + * Update a remote Actor object by actor URL (guid). | |
| 635 | + * | |
| 636 | + * @deprecated 7.4.0 Use {@see Remote_Actors::update()} | |
| 637 | + * | |
| 638 | + * @param int|\WP_Post $post The post ID or object. | |
| 639 | + * @param array|Actor $actor The ActivityPub actor object as associative array (must include 'id'). | |
| 640 | + * | |
| 641 | + * @return int|\WP_Error The post ID or WP_Error. | |
| 642 | + */ | |
| 643 | + public static function update( $post, $actor ) { | |
| 644 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::update' ); | |
| 645 | + return Remote_Actors::update( $post, $actor ); | |
| 646 | + } | |
| 647 | + | |
| 648 | + /** | |
| 649 | + * Delete a remote actor object by actor URL (guid). | |
| 650 | + * | |
| 651 | + * @deprecated 7.4.0 Use {@see Remote_Actors::delete()} | |
| 652 | + * | |
| 653 | + * @param int $post_id The post ID. | |
| 654 | + * | |
| 655 | + * @return bool True on success, false on failure. | |
| 656 | + */ | |
| 657 | + public static function delete( $post_id ) { | |
| 658 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::delete' ); | |
| 659 | + return Remote_Actors::delete( $post_id ); | |
| 660 | + } | |
| 661 | + | |
| 662 | + /** | |
| 663 | + * Get a remote actor post by actor URI (guid). | |
| 664 | + * | |
| 665 | + * @deprecated 7.4.0 Use {@see Remote_Actors::get_by_uri()} | |
| 666 | + * | |
| 667 | + * @param string $actor_uri The actor URI. | |
| 668 | + * | |
| 669 | + * @return \WP_Post|\WP_Error Post object or WP_Error if not found. | |
| 670 | + */ | |
| 671 | + public static function get_remote_by_uri( $actor_uri ) { | |
| 672 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::get_by_uri' ); | |
| 673 | + return Remote_Actors::get_by_uri( $actor_uri ); | |
| 674 | + } | |
| 675 | + | |
| 676 | + /** | |
| 677 | + * Lookup a remote actor post by actor URI (guid), fetching from remote if not found locally. | |
| 678 | + * | |
| 679 | + * @deprecated 7.4.0 Use {@see Remote_Actors::fetch_by_uri()} | |
| 680 | + * | |
| 681 | + * @param string $actor_uri The actor URI. | |
| 682 | + * | |
| 683 | + * @return \WP_Post|\WP_Error Post object or WP_Error if not found. | |
| 684 | + */ | |
| 685 | + public static function fetch_remote_by_uri( $actor_uri ) { | |
| 686 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::fetch_by_uri' ); | |
| 687 | + return Remote_Actors::fetch_by_uri( $actor_uri ); | |
| 688 | + } | |
| 689 | + | |
| 690 | + /** | |
| 691 | + * Store an error that occurred when sending an ActivityPub message to a follower. | |
| 692 | + * | |
| 693 | + * The error will be stored in post meta. | |
| 694 | + * | |
| 695 | + * @deprecated 7.4.0 Use {@see Remote_Actors::add_error()} | |
| 696 | + * | |
| 697 | + * @param int $post_id The ID of the WordPress Custom-Post-Type. | |
| 698 | + * @param string|\WP_Error $error The error message. | |
| 699 | + * | |
| 700 | + * @return int|false The meta ID on success, false on failure. | |
| 701 | + */ | |
| 702 | + public static function add_error( $post_id, $error ) { | |
| 703 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::add_error' ); | |
| 704 | + return Remote_Actors::add_error( $post_id, $error ); | |
| 705 | + } | |
| 706 | + | |
| 707 | + /** | |
| 708 | + * Count the errors for an actor. | |
| 709 | + * | |
| 710 | + * @deprecated 7.4.0 Use {@see Remote_Actors::count_errors()} | |
| 711 | + * | |
| 712 | + * @param int $post_id The ID of the WordPress Custom-Post-Type. | |
| 713 | + * | |
| 714 | + * @return int The number of errors. | |
| 715 | + */ | |
| 716 | + public static function count_errors( $post_id ) { | |
| 717 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::count_errors' ); | |
| 718 | + return Remote_Actors::count_errors( $post_id ); | |
| 719 | + } | |
| 720 | + | |
| 721 | + /** | |
| 722 | + * Get all error messages for an actor. | |
| 723 | + * | |
| 724 | + * @deprecated 7.4.0 Use {@see Remote_Actors::get_errors()} | |
| 725 | + * | |
| 726 | + * @param int $post_id The post ID. | |
| 727 | + * | |
| 728 | + * @return string[] Array of error messages. | |
| 729 | + */ | |
| 730 | + public static function get_errors( $post_id ) { | |
| 731 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::get_errors' ); | |
| 732 | + return Remote_Actors::get_errors( $post_id ); | |
| 733 | + } | |
| 734 | + | |
| 735 | + /** | |
| 736 | + * Clear all errors for an actor. | |
| 737 | + * | |
| 738 | + * @deprecated 7.4.0 Use {@see Remote_Actors::clear_errors()} | |
| 739 | + * | |
| 740 | + * @param int $post_id The ID of the WordPress Custom-Post-Type. | |
| 741 | + * | |
| 742 | + * @return bool True on success, false on failure. | |
| 743 | + */ | |
| 744 | + public static function clear_errors( $post_id ) { | |
| 745 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::clear_errors' ); | |
| 746 | + return Remote_Actors::clear_errors( $post_id ); | |
| 747 | + } | |
| 748 | + | |
| 749 | + /** | |
| 750 | + * Get all remote actors (Custom Post Type) that had errors. | |
| 751 | + * | |
| 752 | + * @deprecated 7.4.0 Use {@see Remote_Actors::get_faulty()} | |
| 753 | + * | |
| 754 | + * @param int $number Optional. Number of actors to return. Default 20. | |
| 755 | + * | |
| 756 | + * @return \WP_Post[] Array of faulty actor posts. | |
| 757 | + */ | |
| 758 | + public static function get_faulty( $number = 20 ) { | |
| 759 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::get_faulty' ); | |
| 760 | + return Remote_Actors::get_faulty( $number ); | |
| 761 | + } | |
| 762 | + | |
| 763 | + /** | |
| 764 | + * Get all remote actor posts not updated for a given time. | |
| 765 | + * | |
| 766 | + * @deprecated 7.4.0 Use {@see Remote_Actors::get_outdated()} | |
| 767 | + * | |
| 768 | + * @param int $number Optional. Limits the result. Default 50. | |
| 769 | + * @param int $older_than Optional. The time in seconds. Default DAY_IN_SECONDS. | |
| 770 | + * | |
| 771 | + * @return \WP_Post[] The list of actors. | |
| 772 | + */ | |
| 773 | + public static function get_outdated( $number = 50, $older_than = DAY_IN_SECONDS ) { | |
| 774 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::get_outdated' ); | |
| 775 | + return Remote_Actors::get_outdated( $number, $older_than ); | |
| 776 | + } | |
| 777 | + | |
| 778 | + /** | |
| 779 | + * Convert a custom post type input to an Activitypub\Activity\Actor. | |
| 780 | + * | |
| 781 | + * @deprecated 7.4.0 Use {@see Remote_Actors::get_actor()} | |
| 782 | + * | |
| 783 | + * @param int|\WP_Post $post The post ID or object. | |
| 784 | + * | |
| 785 | + * @return Actor|\WP_Error The actor object or WP_Error on failure. | |
| 786 | + */ | |
| 787 | + public static function get_actor( $post ) { | |
| 788 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::get_actor' ); | |
| 789 | + return Remote_Actors::get_actor( $post ); | |
| 790 | + } | |
| 791 | + | |
| 792 | + /** | |
| 793 | + * Get public key from key_id. | |
| 794 | + * | |
| 795 | + * @deprecated 7.4.0 Use {@see Remote_Actors::get_public_key()} | |
| 796 | + * | |
| 797 | + * @param string $key_id The URL to the public key. | |
| 798 | + * | |
| 799 | + * @return resource|\WP_Error The public key resource or WP_Error. | |
| 800 | + */ | |
| 801 | + public static function get_remote_key( $key_id ) { | |
| 802 | + _deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::get_public_key' ); | |
| 803 | + return Remote_Actors::get_public_key( $key_id ); | |
| 804 | + } | |
| 805 | + | |
| 806 | + /** | |
| 807 | + * Normalize actor identifier to a URI. | |
| 808 | + * | |
| 809 | + * Handles webfinger addresses, URLs without schemes, objects, and arrays. | |
| 810 | + * | |
| 811 | + * @deprecated 7.4.0 Use {@see Remote_Actors::normalize_identifier()} | |
| 812 | + * | |
| 813 | + * @param string|object|array $actor Actor URI, webfinger address, actor object, or array. | |
| 814 | + * @return string|null Normalized actor URI or null if unable to resolve. | |
| 815 | + */ | |
| 816 | + public static function normalize_identifier( $actor ) { | |
| 817 | + _deprecated_function( __METHOD__, '7.4.0', 'Remote_Actors::normalize_identifier' ); | |
| 818 | + return Remote_Actors::normalize_identifier( $actor ); | |
| 603 | 819 | } |
| 604 | 820 | |
| 605 | 821 | /** |
| 606 | 822 | * Determine if social graph (followers and following) should be shown for a given user. |