diff --git a/projects/packages/publicize/changelog/update-social-settings-route-registration b/projects/packages/publicize/changelog/update-social-settings-route-registration new file mode 100644 index 0000000000000..3359660e24d14 --- /dev/null +++ b/projects/packages/publicize/changelog/update-social-settings-route-registration @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Only register social/settings endpoint if Jetpack version does not have it diff --git a/projects/packages/publicize/src/class-publicize-script-data.php b/projects/packages/publicize/src/class-publicize-script-data.php index abbba41c296e5..2ae4dc2c8768a 100644 --- a/projects/packages/publicize/src/class-publicize-script-data.php +++ b/projects/packages/publicize/src/class-publicize-script-data.php @@ -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' => class_exists( 'Jetpack' ) ? 'settings' : 'social/settings', + 'socialToggleBase' => Utils::should_use_jetpack_module_endpoint() ? 'settings' : 'social/settings', ); $specific_paths = array(); diff --git a/projects/packages/publicize/src/class-publicize-utils.php b/projects/packages/publicize/src/class-publicize-utils.php index ef31f3c8ee24d..b181681d05172 100644 --- a/projects/packages/publicize/src/class-publicize-utils.php +++ b/projects/packages/publicize/src/class-publicize-utils.php @@ -109,4 +109,15 @@ public static function assert_is_wpcom( $method ) { throw new \Exception( esc_html( "Method $method can only be called on WordPress.com." ) ); } } + + /** + * Check if the new module endpoint is available in the used Jetpack version. + * We need the module status in response that's why we do the version check https://github.com/Automattic/jetpack/pull/41461/files#diff-f8e5ef1115599de750b64143dd1901554254eddd95ab4371b6b6b3b2a5914224R638-R642. + * More: https://github.com/Automattic/jetpack/pull/41596. + * + * @return bool + */ + public static function should_use_jetpack_module_endpoint() { + return class_exists( 'Jetpack' ) && defined( 'JETPACK__VERSION' ) && ( version_compare( (string) JETPACK__VERSION, '14.3', '>=' ) ); + } } diff --git a/projects/plugins/social/changelog/update-social-settings-route-registration b/projects/plugins/social/changelog/update-social-settings-route-registration new file mode 100644 index 0000000000000..3359660e24d14 --- /dev/null +++ b/projects/plugins/social/changelog/update-social-settings-route-registration @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Only register social/settings endpoint if Jetpack version does not have it diff --git a/projects/plugins/social/src/class-rest-settings-controller.php b/projects/plugins/social/src/class-rest-settings-controller.php index afd4db3c2eb09..ba858acfa1c55 100644 --- a/projects/plugins/social/src/class-rest-settings-controller.php +++ b/projects/plugins/social/src/class-rest-settings-controller.php @@ -9,6 +9,7 @@ namespace Automattic\Jetpack\Social; use Automattic\Jetpack\Modules; +use Automattic\Jetpack\Publicize\Publicize_Utils; use Jetpack_Social; use WP_Error; use WP_REST_Controller; @@ -28,30 +29,36 @@ class REST_Settings_Controller extends WP_REST_Controller { public function register_rest_routes() { register_rest_route( 'jetpack/v4', - '/social/settings', + '/social/review-dismiss', 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' ), + 'callback' => array( $this, 'update_review_dismissed' ), + 'permission_callback' => array( $this, 'require_publish_posts_permission_callback' ), 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), ), ) ); + + 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/review-dismiss', + '/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_review_dismissed' ), - 'permission_callback' => array( $this, 'require_publish_posts_permission_callback' ), + '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 ), ), )