Skip to content

Commit

Permalink
Publicize: Adjust how the Connections Post Field is initialised
Browse files Browse the repository at this point in the history
In order to make it compatible with use on WPCOM we need to adjust how
the Connections Post Field is initialised. This adds a constructor to
handle registering the `rest_init` hook, and adds the WPCOM specific
logic.
  • Loading branch information
pablinos committed Dec 13, 2024
1 parent 4ff8c90 commit b49bf09
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Adjusted the initialisation logic for the connections field.
13 changes: 13 additions & 0 deletions projects/packages/publicize/src/class-connections-post-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ class Connections_Post_Field {
*/
public $memoized_updates = array();

/**
* Constructor.
*/
public function __construct() {
// Adding on a higher priority to make sure we're the first field registered.
// The priority parameter can be removed once we deprecate WPCOM_REST_API_V2_Post_Publicize_Connections_Field
add_action( 'rest_api_init', array( $this, 'register_fields' ), 5 );
}

/**
* Registers the jetpack_publicize_connections field. Called
* automatically on `rest_api_init()`.
Expand Down Expand Up @@ -490,3 +499,7 @@ private function is_valid_for_context( $schema, $context ) {
return empty( $schema['context'] ) || in_array( $context, $schema['context'], true );
}
}

if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
wpcom_rest_api_v2_load_plugin( 'Automattic\Jetpack\Publicize\Connections_Post_Field' );

Check failure on line 504 in projects/packages/publicize/src/class-connections-post-field.php

View workflow job for this annotation

GitHub Actions / Static analysis

UndefError PhanUndeclaredFunction Call to undeclared function \wpcom_rest_api_v2_load_plugin()
}
5 changes: 1 addition & 4 deletions projects/packages/publicize/src/class-publicize-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ public static function on_jetpack_feature_publicize_enabled() {

if ( ! isset( $publicize_ui ) ) {
$publicize_ui = new Publicize_UI();

}

// Adding on a higher priority to make sure we're the first field registered.
// The priority parameter can be removed once we deprecate WPCOM_REST_API_V2_Post_Publicize_Connections_Field
add_action( 'rest_api_init', array( new Connections_Post_Field(), 'register_fields' ), 5 );
new Connections_Post_Field();

Check failure on line 39 in projects/packages/publicize/src/class-publicize-setup.php

View workflow job for this annotation

GitHub Actions / Static analysis

NOOPError PhanNoopNew Unused result of new object creation expression in new Connections_Post_Field() (this may be called for the side effects of the non-empty constructor or destructor)
add_action( 'rest_api_init', array( new REST_Controller(), 'register_rest_routes' ) );
add_action( 'current_screen', array( static::class, 'init_sharing_limits' ) );

Expand Down

0 comments on commit b49bf09

Please sign in to comment.