'web', 'url' => 'plugins.php?page=wc-beta-tester-version-picker', 'title' => 'Version switch result', 'plugin' => $plugin_name, 'version' => $version, 'nonce' => wp_unslash( $_GET['_wpnonce'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ); $skin = new Automatic_Upgrader_Skin( $skin_args ); $upgrader = new WC_Beta_Tester_Plugin_Upgrader( $skin ); $result = $upgrader->switch_version( $plugin ); // Try to reactivate. activate_plugin( $plugin, '', is_network_admin(), true ); if ( is_wp_error( $skin->result ) ) { throw new Exception( $skin->result->get_error_message() ); } elseif ( false === $result ) { throw new Exception( __( 'Update failed', 'woocommerce-beta-tester' ) ); } wp_safe_redirect( admin_url( 'plugins.php?page=wc-beta-tester-version-picker&switched=' . rawurlencode( $version ) ) ); exit; } catch ( Exception $e ) { if ( class_exists( 'WC_Admin_Notices' ) ) { WC_Admin_Notices::add_custom_notice( $plugin . '_update_error', sprintf( // translators: 1: plugin name, 2: error message. __( '%1$s could not be updated (%2$s).', 'woocommerce-beta-tester' ), $plugin, $e->getMessage() ) ); wp_safe_redirect( admin_url( 'plugins.php?page=wc-beta-tester-version-picker' ) ); exit; } else { wp_die( esc_html( $e->getMessage() ) ); } } } /** * Add options page to menu. * * @return void */ public function add_to_menus() { add_submenu_page( 'plugins.php', __( 'WooCommerce Version Switch', 'woocommerce-beta-tester' ), __( 'WooCommerce Version Switch', 'woocommerce-beta-tester' ), 'install_plugins', 'wc-beta-tester-version-picker', array( $this, 'select_versions_form_html' ) ); } /** * Return HTML code representation of list of WooCommerce versions for the selected channel. * * @param string $channel Filter versions by channel: all|beta|rc|stable. * @return string */ public function get_versions_html( $channel ) { $tags = WC_Beta_Tester::instance()->get_tags( $channel ); if ( ! $tags ) { return ''; } usort( $tags, 'version_compare' ); $tags = array_reverse( $tags ); $versions_html = ''; // The nonce is validated upstream. // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! empty( $_GET['switched'] ) ) { /* translators: %s: WooCoomerce version */ $versions_html .= '
' . sprintf( esc_html__( 'Successfully switched version to %s.', 'woocommerce-beta-tester' ), esc_html( sanitize_text_field( wp_unslash( $_GET['switched'] ) ) ) ) . '