Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publicize: Adjust how the Connections Post Field is initialised #40613

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
*/
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 @@
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 @@

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be initialized on Simple sites?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the on_jetpack_feature_publicize_enabled method here is called on WPCOM. We need an unconditional initialization for WPCOM, the way we do for assets.

Probably, we should have a method named unconditional_initialization inside Publicize_Setup class to add all that logic there and also more that assets initialization logic into that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we would need to adjust the loading of it on WPCOM too

add_action( 'rest_api_init', array( new REST_Controller(), 'register_rest_routes' ) );
add_action( 'current_screen', array( static::class, 'init_sharing_limits' ) );

Expand Down
Loading