diff --git a/projects/packages/publicize/changelog/update-post-connections-field-config b/projects/packages/publicize/changelog/update-post-connections-field-config new file mode 100644 index 0000000000000..0dbad0f9b08d9 --- /dev/null +++ b/projects/packages/publicize/changelog/update-post-connections-field-config @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Adjusted the initialisation logic for the connections field. diff --git a/projects/packages/publicize/src/class-connections-post-field.php b/projects/packages/publicize/src/class-connections-post-field.php index 6d632ee5ccbb3..a0277dd73bca7 100644 --- a/projects/packages/publicize/src/class-connections-post-field.php +++ b/projects/packages/publicize/src/class-connections-post-field.php @@ -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()`. @@ -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' ); +} diff --git a/projects/packages/publicize/src/class-publicize-setup.php b/projects/packages/publicize/src/class-publicize-setup.php index 383ef289fab5e..091517911b906 100644 --- a/projects/packages/publicize/src/class-publicize-setup.php +++ b/projects/packages/publicize/src/class-publicize-setup.php @@ -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(); add_action( 'rest_api_init', array( new REST_Controller(), 'register_rest_routes' ) ); add_action( 'current_screen', array( static::class, 'init_sharing_limits' ) );