is_writable( $path ) && $fs->is_writable( dirname( $path ) ); } /** * Reads the file's trimmed content. Callers MUST check `can_take_over()` * first — kept as a separate step (rather than folded into a combined * take-over method) so a caller can apply the migrated content to its * own settings BEFORE attempting `rename_to_backup()`, matching the * original robots.txt behavior: nothing migrated is lost even on the * rare case the rename itself then fails. */ public static function read_content( string $path ): string { return trim( (string) file_get_contents( $path ) ); } /** * Renames the file to a backup (`{path}.acez-backup`, or a timestamped * variant if that name is already taken). Returns whether the rename * succeeded. */ public static function rename_to_backup( string $path ): bool { $fs = self::wp_filesystem(); if ( null === $fs ) { return false; } $backup = $path . '.acez-backup'; if ( file_exists( $backup ) ) { $backup = $path . '.acez-backup-' . gmdate( 'Ymd-His' ); } return $fs->move( $path, $backup ); } }