Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gmjuhasz committed Feb 7, 2025
1 parent 78974f5 commit 0df6110
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public static function get_api_paths() {
$commom_paths = array(
'refreshConnections' => '/wpcom/v2/publicize/connections?test_connections=1',
// The complete path will be like `/jetpack/v4/social/settings`.
'socialToggleBase' => Utils::has_new_module_endpoint() ? 'settings' : 'social/settings',
'socialToggleBase' => Utils::should_use_jetpack_module_endpoint() ? 'settings' : 'social/settings',
);

$specific_paths = array();
Expand Down
5 changes: 3 additions & 2 deletions projects/packages/publicize/src/class-publicize-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ public static function assert_is_wpcom( $method ) {

/**
* Check if the new module endpoint is available in the used Jetpack version.
* More: https://github.com/Automattic/jetpack-reach/issues/794
*
* @return bool
*/
public static function has_new_module_endpoint() {
public static function should_use_jetpack_module_endpoint() {
// @phan-suppress-next-line PhanTypeMismatchArgumentNullableInternal - Phan thinks JETPACK__VERSION is not a string (it is).

Check failure on line 120 in projects/packages/publicize/src/class-publicize-utils.php

View workflow job for this annotation

GitHub Actions / Static analysis

Plugin UnusedPluginSuppression Plugin BuiltinSuppressionPlugin suppresses issue PhanTypeMismatchArgumentNullableInternal on this line but this suppression is unused or suppressed elsewhere FAQ on Phan issues: pdWQjU-Jb-p2
return class_exists( 'Jetpack' ) && defined( 'JETPACK__VERSION' ) && ( version_compare( JETPACK__VERSION, '14.3', '>=' ) );
return class_exists( 'Jetpack' ) && defined( 'JETPACK__VERSION' ) && ( version_compare( (string) JETPACK__VERSION, '14.3', '>=' ) );
}
}
46 changes: 24 additions & 22 deletions projects/plugins/social/src/class-rest-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,6 @@ class REST_Settings_Controller extends WP_REST_Controller {
* @static
*/
public function register_rest_routes() {
// If the site has an older version of Jetpack we still need to register the route.
if ( ! Publicize_Utils::has_new_module_endpoint() ) {
register_rest_route(
'jetpack/v4',
'/social/settings',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
'permission_callback' => array( $this, 'require_admin_privilege_callback' ),
'args' => $this->get_endpoint_args_for_item_schema(),
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'update_item' ),
'permission_callback' => array( $this, 'require_admin_privilege_callback' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
),
)
);
}

register_rest_route(
'jetpack/v4',
'/social/review-dismiss',
Expand All @@ -61,6 +39,30 @@ public function register_rest_routes() {
),
)
);

if ( Publicize_Utils::should_use_jetpack_module_endpoint() ) {
return;
}

// If the site has an older version of Jetpack we still need to register the route.
register_rest_route(
'jetpack/v4',
'/social/settings',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
'permission_callback' => array( $this, 'require_admin_privilege_callback' ),
'args' => $this->get_endpoint_args_for_item_schema(),
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'update_item' ),
'permission_callback' => array( $this, 'require_admin_privilege_callback' ),
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
),
)
);
}

/**
Expand Down

0 comments on commit 0df6110

Please sign in to comment.