*/ protected function output_properties(): array { return array_merge( parent::output_properties(), array( 'plugin' => array( 'type' => 'string' ) ) ); } /** * Whether the plugin was active before its files were replaced. * * @since 0.0.45 * @param array $asset Resolved asset. * @return array */ protected function before_install( array $asset ): array { if ( ! function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } return array( 'was_active' => is_plugin_active( (string) $asset['plugin_file'] ) ); } /** * Put the plugin back in the active list if that is where it was found. * * An overwrite clears the destination, which deactivates the plugin as a side effect the caller * never asked for. Rolling back and silently deactivating would look like the new version * crashing the site. * * @since 0.0.45 * @param array $asset Resolved asset. * @param array $state State from before_install(). * @param string $version Version now installed. * @return array */ protected function after_install( array $asset, array $state, string $version ): array { $plugin_file = (string) $asset['plugin_file']; $was_active = ! empty( $state['was_active'] ); $reactivated = true; if ( $was_active && ! is_plugin_active( $plugin_file ) ) { $activated = activate_plugin( $plugin_file ); $reactivated = ! is_wp_error( $activated ); } $fields = array( 'plugin' => $plugin_file, 'was_active' => $was_active, 'reactivated' => $reactivated, 'message' => sprintf( /* translators: 1: plugin name, 2: version */ __( '"%1$s" is now on version %2$s.', 'acrossai-abilities-manager' ), (string) $asset['name'], $version ), ); if ( $was_active && ! $reactivated ) { $fields['message'] .= ' ' . __( 'It was active before the change but could not be reactivated — the version you moved to may be incompatible with this site. Check it before activating manually.', 'acrossai-abilities-manager' ); } return $fields; } }