'warning', 'message' => sprintf( /* translators: 1: wrong folder name, 2: correct folder name */ __( 'Two AANYA plugin folders were found (%1$s and %2$s). Deactivate and delete the versioned one, then keep only “%2$s” so updates and reviews work from WordPress.org.', 'aanya-ai-chatbot' ), $old_slug, self::EXPECTED_SLUG ), ), 10 * MINUTE_IN_SECONDS ); delete_transient( 'aanya_install_path_lock' ); return; } if ( ! is_writable( dirname( $old_dir ) ) || ! is_writable( $old_dir ) ) { set_transient( 'aanya_install_path_notice', array( 'type' => 'error', 'message' => sprintf( /* translators: 1: wrong folder, 2: correct folder */ __( 'AANYA is installed as “%1$s”. Rename that folder to “%2$s” (or reinstall from WordPress.org → Plugins → Add New) so automatic updates work. Your host may need to allow renaming under wp-content/plugins.', 'aanya-ai-chatbot' ), $old_slug, self::EXPECTED_SLUG ), ), 10 * MINUTE_IN_SECONDS ); delete_transient( 'aanya_install_path_lock' ); return; } // phpcs:ignore WordPress.WP.AlternativeFunctions.rename_rename -- intentional filesystem rename of plugin directory. $renamed = @rename( $old_dir, $new_dir ); if ( ! $renamed ) { set_transient( 'aanya_install_path_notice', array( 'type' => 'error', 'message' => sprintf( /* translators: 1: wrong folder, 2: correct folder */ __( 'Could not auto-rename “%1$s” to “%2$s”. Please delete this plugin and install “AANYA AI Chatbot” from WordPress.org (Plugins → Add New), or rename the folder via FTP/File Manager.', 'aanya-ai-chatbot' ), $old_slug, self::EXPECTED_SLUG ), ), 10 * MINUTE_IN_SECONDS ); delete_transient( 'aanya_install_path_lock' ); return; } self::rewire_active_plugins( $old_bas, $new_bas ); set_transient( 'aanya_install_path_notice', array( 'type' => 'success', 'message' => sprintf( /* translators: %s: correct folder name */ __( 'AANYA install path was fixed automatically. The plugin folder is now “%s”, so WordPress.org updates can reach this site.', 'aanya-ai-chatbot' ), self::EXPECTED_SLUG ), ), 10 * MINUTE_IN_SECONDS ); delete_transient( 'aanya_install_path_lock' ); // Reload from the new path so this request does not keep using the old directory. wp_safe_redirect( add_query_arg( 'aanya_path_fixed', '1', admin_url( 'plugins.php' ) ) ); exit; } /** * Update active plugin basenames after rename. * * @param string $old_bas Old plugin basename. * @param string $new_bas New plugin basename. */ private static function rewire_active_plugins( $old_bas, $new_bas ) { $active = (array) get_option( 'active_plugins', array() ); $changed = false; foreach ( $active as $i => $basename ) { if ( $basename === $old_bas ) { $active[ $i ] = $new_bas; $changed = true; } } if ( $changed ) { update_option( 'active_plugins', array_values( array_unique( $active ) ) ); } if ( is_multisite() ) { $network = (array) get_site_option( 'active_sitewide_plugins', array() ); if ( isset( $network[ $old_bas ] ) ) { $network[ $new_bas ] = $network[ $old_bas ]; unset( $network[ $old_bas ] ); update_site_option( 'active_sitewide_plugins', $network ); } } } /** * Flash notice after rename / conflict / failure. */ public static function render_notices() { if ( ! current_user_can( 'manage_options' ) ) { return; } $notice = get_transient( 'aanya_install_path_notice' ); if ( ! is_array( $notice ) || empty( $notice['message'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display-only query flag after redirect. if ( empty( $_GET['aanya_path_fixed'] ) ) { return; } $notice = array( 'type' => 'success', 'message' => sprintf( /* translators: %s: correct folder name */ __( 'AANYA install path was fixed automatically. The plugin folder is now “%s”.', 'aanya-ai-chatbot' ), self::EXPECTED_SLUG ), ); } else { delete_transient( 'aanya_install_path_notice' ); } $type = isset( $notice['type'] ) ? $notice['type'] : 'info'; $class = 'notice-info'; if ( 'success' === $type ) { $class = 'notice-success'; } elseif ( 'error' === $type ) { $class = 'notice-error'; } elseif ( 'warning' === $type ) { $class = 'notice-warning'; } printf( '

%2$s

', esc_attr( $class ), esc_html( $notice['message'] ) ); } }