id, array( 'dashboard', 'plugins', 'plugins-network' ), true ) || false !== strpos( (string) $screen->id, 'aooshop' ) ) ) {
return;
}
$names = array();
foreach ( $active as $basename ) {
$names[] = 'wp-aoocommerce/wp-aoocommerce.php' === $basename ? 'AooCommerce for WordPress' : 'AooCommerce';
}
$url = wp_nonce_url( admin_url( 'admin-post.php?action=aooshop_switch_legacy' ), 'aooshop_switch_legacy' );
printf(
'
',
esc_html__( 'AOO Shop is waiting.', 'aoo-shop' ),
esc_html(
sprintf(
/* translators: %s: name(s) of the earlier plugin copy, e.g. "AooCommerce". */
__( 'The earlier copy of this plugin ("%s") is still active, so AOO Shop is paused. Deactivate the earlier copy to switch — your connection, API key and settings are kept.', 'aoo-shop' ),
implode( '", "', array_unique( $names ) )
)
),
esc_url( $url ),
esc_html__( 'Deactivate the old plugin and switch', 'aoo-shop' )
);
}
/** admin-post handler of the notice button. */
function aooshop_switch_handle() {
if ( ! current_user_can( 'activate_plugins' ) ) {
wp_die( esc_html__( 'Sorry, you are not allowed to manage plugins.', 'aoo-shop' ), 403 );
}
check_admin_referer( 'aooshop_switch_legacy' );
aooshop_switch_deactivate_legacy();
wp_safe_redirect( admin_url( 'plugins.php' ) );
exit;
}
/** Activation chores that could not run while a legacy copy owned the classes (template page, tables, roles, rewrite). */
function aooshop_switch_finish() {
if ( ! get_option( 'aooshop_pending_activation' ) ) {
return;
}
add_action(
'init',
static function () {
delete_option( 'aooshop_pending_activation' );
AooShop_Plugin::activate();
},
20
);
}
/** Keep the shared data when a legacy copy is deleted while this one runs (their uninstall.php checks keep_data). */
function aooshop_switch_guard_uninstall() {
add_action(
'pre_uninstall_plugin',
static function ( $plugin ) {
if ( ! in_array( $plugin, aooshop_switch_legacy_plugins(), true ) ) {
return;
}
$keep = static function ( $value ) {
$value = is_array( $value ) ? $value : array();
$value['keep_data'] = 1;
return $value;
};
add_filter( 'option_aooshop_settings', $keep );
add_filter( 'default_option_aooshop_settings', $keep );
}
);
}
}
/*
* 0.7.0 API — called by the `aoocommerce/` copy when it loads after this file (it then skips its own legacy-switch.php).
* In that copy "legacy" means only `wp-aoocommerce/`; it must keep running while AOO Shop is dormant.
*/
if ( ! function_exists( 'aooshop_legacy_is_active' ) ) {
/** 0.7.0: is `wp-aoocommerce/wp-aoocommerce.php` active? */
function aooshop_legacy_is_active() {
return aooshop_switch_plugin_active( 'wp-aoocommerce/wp-aoocommerce.php' );
}
}
if ( ! function_exists( 'aooshop_legacy_dormant' ) ) {
/**
* 0.7.0: the calling copy is dormant (`wp-aoocommerce/` owns the classes) — nothing to hook here: AOO Shop's own
* notice already covers every legacy copy.
*
* @param string $main_file Main file of the calling copy.
*/
function aooshop_legacy_dormant( $main_file ) {
unset( $main_file );
}
}
if ( ! function_exists( 'aooshop_legacy_guard_uninstall' ) ) {
/** 0.7.0: keep shared data when another copy is deleted. */
function aooshop_legacy_guard_uninstall() {
aooshop_switch_guard_uninstall();
}
}
if ( ! function_exists( 'aooshop_legacy_finish_switch' ) ) {
/** 0.7.0: run pending activation chores. */
function aooshop_legacy_finish_switch() {
aooshop_switch_finish();
}
}