Skip to content

Commit

Permalink
Jetpack: Add shim for 13.9+ to prevent Jetpack_SSO fatal and admin no…
Browse files Browse the repository at this point in the history
…tices for 13.5+ (#5937)

* Jetpack: Add shim for 13.9+ to prevent Jetpack_SSO fatal and admin notice for 13.5+

* Need to extend the darn class to prevent undefined method fatals

* use Capability Condition

* Revert "use Capability Condition"

This reverts commit f441783.

* remove condition since it is super admin by default if no cap condition specified
  • Loading branch information
rebeccahum committed Oct 16, 2024
1 parent a3223cc commit 5dd8415
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
17 changes: 17 additions & 0 deletions admin-notice/admin-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,20 @@ function () use ( $admin_notice_controller ) {
do_action( 'vip_admin_notice_init', $admin_notice_controller );
}
);

add_action(
'vip_admin_notice_init',
function ( $admin_notice_controller ) {
$message = 'Heads up! Your site is using a deprecated plugin <a href="https://github.com/Automattic/jetpack-force-2fa/">jetpack-force-2fa</a>. This functionality is already included in Jetpack as of version 13.5. Please remove the plugin to avoid potential conflicts with future Jetpack updates.';
$admin_notice_controller->add(
new Admin_Notice(
$message,
[
new Expression_Condition( class_exists( 'Jetpack_Force_2FA' ) && class_exists( 'Jetpack' ) && defined( 'JETPACK__VERSION' ) && version_compare( JETPACK__VERSION, '13.5', '>=' ) ),
],
'deprecated-standalone-jetpack-2fa-plugin',
'error'
)
);
}
);
7 changes: 7 additions & 0 deletions vip-jetpack/jetpack-sso-dummy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

if ( ! class_exists( '\Automattic\Jetpack\Connection\SSO' ) ) {
return;
}

class Jetpack_SSO extends \Automattic\Jetpack\Connection\SSO {}
12 changes: 12 additions & 0 deletions vip-jetpack/vip-jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,15 @@ function vip_prevent_jetpack_post_by_email_database_noise() {
unset( $_POST['invite_user_wpcom'] );
}
});

/**
* Jetpack 13.9 removes the legacy Jetpack_SSO class. Unfortunately, this class is still used by
* the deprecated standalone jetpack-force-2fa plugin (which is still in use by some). This is a dummy
* class to prevent fatal errors when the standalone plugin is enabled.
*/
add_action( 'plugins_loaded', function () {
if ( class_exists( 'Jetpack_Force_2FA' ) && ! class_exists( 'Jetpack_SSO' ) && class_exists( 'Jetpack' ) &&
defined( 'JETPACK__VERSION' ) && version_compare( JETPACK__VERSION, '13.9', '>=' ) ) {
require_once __DIR__ . '/jetpack-sso-dummy.php';
}
} );

0 comments on commit 5dd8415

Please sign in to comment.